maestro-bundle 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/bundle-ai-agents/skills/agent-orchestration/SKILL.md +107 -41
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/graph-patterns.md +50 -0
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/routing-strategies.md +47 -0
- package/templates/bundle-ai-agents/skills/api-design/SKILL.md +125 -16
- package/templates/bundle-ai-agents/skills/api-design/references/pydantic-patterns.md +72 -0
- package/templates/bundle-ai-agents/skills/api-design/references/rest-conventions.md +51 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/SKILL.md +113 -21
- package/templates/bundle-ai-agents/skills/clean-architecture/references/dependency-injection.md +60 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/references/layer-rules.md +56 -0
- package/templates/bundle-ai-agents/skills/context-engineering/SKILL.md +104 -36
- package/templates/bundle-ai-agents/skills/context-engineering/references/compression-techniques.md +76 -0
- package/templates/bundle-ai-agents/skills/context-engineering/references/context-budget-calculator.md +45 -0
- package/templates/bundle-ai-agents/skills/database-modeling/SKILL.md +146 -19
- package/templates/bundle-ai-agents/skills/database-modeling/references/index-strategies.md +48 -0
- package/templates/bundle-ai-agents/skills/database-modeling/references/naming-conventions.md +27 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/SKILL.md +124 -15
- package/templates/bundle-ai-agents/skills/docker-containerization/references/compose-patterns.md +97 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/references/dockerfile-checklist.md +37 -0
- package/templates/bundle-ai-agents/skills/eval-testing/SKILL.md +113 -25
- package/templates/bundle-ai-agents/skills/eval-testing/references/eval-types.md +52 -0
- package/templates/bundle-ai-agents/skills/eval-testing/references/golden-dataset-template.md +59 -0
- package/templates/bundle-ai-agents/skills/memory-management/SKILL.md +112 -28
- package/templates/bundle-ai-agents/skills/memory-management/references/memory-tiers.md +41 -0
- package/templates/bundle-ai-agents/skills/memory-management/references/namespace-conventions.md +41 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/SKILL.md +139 -47
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/anti-patterns.md +59 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/prompt-templates.md +75 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/SKILL.md +104 -27
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/chunking-strategies.md +27 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/embedding-models.md +31 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/rag-evaluation.md +39 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/SKILL.md +127 -18
- package/templates/bundle-ai-agents/skills/testing-strategy/references/fixture-patterns.md +81 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/references/naming-conventions.md +69 -0
- package/templates/bundle-base/skills/branch-strategy/SKILL.md +134 -21
- package/templates/bundle-base/skills/branch-strategy/references/branch-rules.md +40 -0
- package/templates/bundle-base/skills/code-review/SKILL.md +123 -38
- package/templates/bundle-base/skills/code-review/references/review-checklist.md +45 -0
- package/templates/bundle-base/skills/commit-pattern/SKILL.md +98 -39
- package/templates/bundle-base/skills/commit-pattern/references/conventional-commits.md +40 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/SKILL.md +110 -19
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandas-cheatsheet.md +63 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandera-schemas.md +44 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/SKILL.md +132 -16
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/compose-patterns.md +82 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/dockerfile-best-practices.md +57 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/SKILL.md +143 -45
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/encoding-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/scaling-guide.md +38 -0
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/SKILL.md +156 -37
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/references/mlflow-commands.md +69 -0
- package/templates/bundle-data-pipeline/skills/model-training/SKILL.md +152 -33
- package/templates/bundle-data-pipeline/skills/model-training/references/evaluation-metrics.md +52 -0
- package/templates/bundle-data-pipeline/skills/model-training/references/model-selection-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/SKILL.md +127 -39
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/chunking-strategies.md +51 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/embedding-models.md +49 -0
- package/templates/bundle-frontend-spa/skills/authentication/SKILL.md +196 -13
- package/templates/bundle-frontend-spa/skills/authentication/references/jwt-security.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/SKILL.md +191 -41
- package/templates/bundle-frontend-spa/skills/component-design/references/accessibility-checklist.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/references/tailwind-patterns.md +65 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/SKILL.md +241 -79
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/playwright-selectors.md +66 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/test-patterns.md +82 -0
- package/templates/bundle-frontend-spa/skills/integration-api/SKILL.md +221 -31
- package/templates/bundle-frontend-spa/skills/integration-api/references/api-patterns.md +81 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/SKILL.md +195 -70
- package/templates/bundle-frontend-spa/skills/react-patterns/references/component-checklist.md +22 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/references/hook-patterns.md +63 -0
- package/templates/bundle-frontend-spa/skills/responsive-layout/SKILL.md +162 -22
- package/templates/bundle-frontend-spa/skills/responsive-layout/references/breakpoint-guide.md +63 -0
- package/templates/bundle-frontend-spa/skills/state-management/SKILL.md +158 -30
- package/templates/bundle-frontend-spa/skills/state-management/references/react-query-config.md +64 -0
- package/templates/bundle-frontend-spa/skills/state-management/references/state-patterns.md +78 -0
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/SKILL.md +135 -45
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/references/gitlab-ci-templates.md +93 -0
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/SKILL.md +63 -21
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-microservices.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/SKILL.md +125 -91
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/references/docker-k8s-commands.md +68 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/SKILL.md +72 -20
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/cross-service-entities.md +36 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/SKILL.md +80 -8
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/references/gateway-config.md +43 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/SKILL.md +115 -22
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/references/kafka-events.md +39 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/SKILL.md +92 -23
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/references/consul-config.md +61 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/SKILL.md +81 -18
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/references/service-patterns.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/references/test-naming.md +55 -0
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/SKILL.md +99 -52
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/SKILL.md +89 -36
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/SKILL.md +123 -23
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/references/liquibase-operations.md +95 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/SKILL.md +106 -19
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/references/security-checklist.md +47 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/SKILL.md +84 -16
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/references/spring-layers.md +41 -0
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/references/test-naming.md +55 -0
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: jhipster-gateway
|
|
3
|
-
description:
|
|
3
|
+
description: Configure the JHipster Gateway with Spring Cloud Gateway, routing, rate limiting, CORS, and frontend Angular. Use when configuring gateway routes, load balancing, rate limiting, or CORS between services.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# JHipster Gateway
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Configure and manage the JHipster Gateway as the single entry point for microservices, handling routing, rate limiting, CORS, and serving the Angular frontend.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
## When to Use
|
|
13
|
+
- When configuring routes to backend microservices
|
|
14
|
+
- When setting up rate limiting on API endpoints
|
|
15
|
+
- When configuring CORS for cross-origin requests
|
|
16
|
+
- When checking health/status of backend services
|
|
17
|
+
- When debugging routing issues
|
|
11
18
|
|
|
12
|
-
##
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Configure service routes with load balancing
|
|
21
|
+
2. Add rate limiting per route
|
|
22
|
+
3. Configure CORS policies
|
|
23
|
+
4. Monitor service health via actuator
|
|
24
|
+
5. Add custom gateway filters
|
|
25
|
+
|
|
26
|
+
## Multi-Step Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Configure Routes
|
|
13
29
|
|
|
14
30
|
```yaml
|
|
15
31
|
# application.yml
|
|
@@ -33,7 +49,7 @@ spring:
|
|
|
33
49
|
- TokenRelay
|
|
34
50
|
```
|
|
35
51
|
|
|
36
|
-
|
|
52
|
+
### Step 2: Add Rate Limiting
|
|
37
53
|
|
|
38
54
|
```yaml
|
|
39
55
|
spring:
|
|
@@ -63,7 +79,7 @@ public KeyResolver userKeyResolver() {
|
|
|
63
79
|
}
|
|
64
80
|
```
|
|
65
81
|
|
|
66
|
-
|
|
82
|
+
### Step 3: Configure CORS
|
|
67
83
|
|
|
68
84
|
```java
|
|
69
85
|
@Bean
|
|
@@ -80,7 +96,7 @@ public CorsWebFilter corsFilter() {
|
|
|
80
96
|
}
|
|
81
97
|
```
|
|
82
98
|
|
|
83
|
-
|
|
99
|
+
### Step 4: Enable Health Monitoring
|
|
84
100
|
|
|
85
101
|
```yaml
|
|
86
102
|
management:
|
|
@@ -93,4 +109,60 @@ management:
|
|
|
93
109
|
enabled: true
|
|
94
110
|
```
|
|
95
111
|
|
|
96
|
-
|
|
112
|
+
```bash
|
|
113
|
+
# View active routes
|
|
114
|
+
curl http://localhost:8080/actuator/gateway/routes
|
|
115
|
+
|
|
116
|
+
# Check service health
|
|
117
|
+
curl http://localhost:8080/actuator/health
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Step 5: Build and Verify
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Build gateway
|
|
124
|
+
./mvnw compile
|
|
125
|
+
|
|
126
|
+
# Run gateway
|
|
127
|
+
./mvnw spring-boot:run
|
|
128
|
+
|
|
129
|
+
# Verify routing works
|
|
130
|
+
curl http://localhost:8080/api/demands
|
|
131
|
+
curl http://localhost:8080/api/agents
|
|
132
|
+
|
|
133
|
+
# Run tests
|
|
134
|
+
./mvnw test
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Resources
|
|
138
|
+
- `references/gateway-config.md` - Gateway routing and filter configuration reference
|
|
139
|
+
|
|
140
|
+
## Examples
|
|
141
|
+
### Example 1: Add a New Service Route
|
|
142
|
+
User asks: "Route /api/bundles to the new bundle-service"
|
|
143
|
+
Response approach:
|
|
144
|
+
1. Add route entry in `application.yml` with `lb://bundle-service` URI
|
|
145
|
+
2. Add path predicate for `/api/bundles/**`
|
|
146
|
+
3. Restart gateway and verify with `curl http://localhost:8080/api/bundles`
|
|
147
|
+
|
|
148
|
+
### Example 2: Add Rate Limiting
|
|
149
|
+
User asks: "Limit the demands API to 10 requests per second"
|
|
150
|
+
Response approach:
|
|
151
|
+
1. Add `RequestRateLimiter` filter to the demand-service route
|
|
152
|
+
2. Configure `replenishRate` and `burstCapacity`
|
|
153
|
+
3. Add `KeyResolver` bean for user-based limiting
|
|
154
|
+
4. Test with load tool or rapid curl requests
|
|
155
|
+
|
|
156
|
+
### Example 3: Debug Routing Issues
|
|
157
|
+
User asks: "Requests to /api/agents return 404"
|
|
158
|
+
Response approach:
|
|
159
|
+
1. Check `curl http://localhost:8080/actuator/gateway/routes` for the route
|
|
160
|
+
2. Verify agent-service is registered in Consul/Eureka
|
|
161
|
+
3. Check agent-service health: `curl http://localhost:8080/actuator/health`
|
|
162
|
+
4. Review gateway logs for routing errors
|
|
163
|
+
|
|
164
|
+
## Notes
|
|
165
|
+
- The Gateway is the single entry point -- all client traffic goes through it
|
|
166
|
+
- `lb://` prefix enables load-balanced routing via service discovery
|
|
167
|
+
- `TokenRelay` filter forwards OAuth2 tokens to downstream services
|
|
168
|
+
- Frontend Angular app is served by the Gateway
|
package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/references/gateway-config.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Gateway Configuration Reference
|
|
2
|
+
|
|
3
|
+
## Route Configuration
|
|
4
|
+
```yaml
|
|
5
|
+
spring:
|
|
6
|
+
cloud:
|
|
7
|
+
gateway:
|
|
8
|
+
routes:
|
|
9
|
+
- id: service-name # Unique route ID
|
|
10
|
+
uri: lb://service-name # Load-balanced URI via discovery
|
|
11
|
+
predicates:
|
|
12
|
+
- Path=/api/resource/** # Path matching
|
|
13
|
+
filters:
|
|
14
|
+
- TokenRelay # Forward OAuth2 token
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Built-in Filters
|
|
18
|
+
| Filter | Purpose |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `TokenRelay` | Forward OAuth2 token to downstream |
|
|
21
|
+
| `RequestRateLimiter` | Rate limit requests |
|
|
22
|
+
| `CircuitBreaker` | Circuit breaker pattern |
|
|
23
|
+
| `Retry` | Retry failed requests |
|
|
24
|
+
| `StripPrefix` | Remove path prefix |
|
|
25
|
+
| `AddRequestHeader` | Add header to request |
|
|
26
|
+
|
|
27
|
+
## Rate Limiting
|
|
28
|
+
```yaml
|
|
29
|
+
filters:
|
|
30
|
+
- name: RequestRateLimiter
|
|
31
|
+
args:
|
|
32
|
+
redis-rate-limiter.replenishRate: 10 # Requests per second
|
|
33
|
+
redis-rate-limiter.burstCapacity: 20 # Max burst
|
|
34
|
+
key-resolver: "#{@userKeyResolver}" # Key resolver bean
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Useful Endpoints
|
|
38
|
+
```bash
|
|
39
|
+
GET /actuator/gateway/routes # List all routes
|
|
40
|
+
GET /actuator/health # Service health
|
|
41
|
+
GET /actuator/gateway/globalfilters # Global filters
|
|
42
|
+
GET /actuator/gateway/routefilters # Route filters
|
|
43
|
+
```
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: jhipster-kafka
|
|
3
|
-
description:
|
|
3
|
+
description: Configure Apache Kafka in JHipster for asynchronous communication between microservices with domain events. Use when setting up messaging, event-driven communication, producers, consumers, or dead letter queues.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
# Kafka
|
|
8
|
+
# Kafka in JHipster Microservices
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Configure Apache Kafka for asynchronous event-driven communication between JHipster microservices using domain events, producers, consumers, and dead letter queues.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
- When setting up asynchronous messaging between services
|
|
14
|
+
- When implementing domain events (DemandCreated, TaskCompleted, etc.)
|
|
15
|
+
- When creating Kafka producers and consumers
|
|
16
|
+
- When configuring dead letter queues for failed messages
|
|
17
|
+
- When designing event schemas
|
|
18
|
+
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Set up Kafka with Docker Compose
|
|
21
|
+
2. Define domain events as Java records
|
|
22
|
+
3. Create Kafka producers
|
|
23
|
+
4. Create idempotent consumers
|
|
24
|
+
5. Configure dead letter queues
|
|
25
|
+
|
|
26
|
+
## Multi-Step Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Start Kafka with Docker Compose
|
|
9
29
|
|
|
10
30
|
```yaml
|
|
11
31
|
# docker-compose/kafka.yml
|
|
@@ -29,26 +49,37 @@ services:
|
|
|
29
49
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
30
50
|
```
|
|
31
51
|
|
|
32
|
-
|
|
52
|
+
```bash
|
|
53
|
+
# Start Kafka
|
|
54
|
+
docker-compose -f docker-compose/kafka.yml up -d
|
|
55
|
+
|
|
56
|
+
# Verify Kafka is running
|
|
57
|
+
docker-compose logs kafka | tail -5
|
|
58
|
+
|
|
59
|
+
# List topics
|
|
60
|
+
docker exec -it kafka kafka-topics --list --bootstrap-server localhost:29092
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Step 2: Design Topics by Bounded Context
|
|
33
64
|
|
|
34
|
-
|
|
|
65
|
+
| Topic | Producer | Consumer | Events |
|
|
35
66
|
|---|---|---|---|
|
|
36
67
|
| `demand-events` | demand-service | agent-service, tracking-service | DemandCreated, DemandDecomposed |
|
|
37
68
|
| `agent-events` | agent-service | demand-service, tracking-service | AgentAllocated, TaskCompleted |
|
|
38
69
|
| `bundle-events` | bundle-service | agent-service | BundleUpdated, SkillAdded |
|
|
39
70
|
| `tracking-events` | tracking-service | gateway (WebSocket) | MetricsUpdated |
|
|
40
71
|
|
|
41
|
-
|
|
72
|
+
### Step 3: Define Domain Events
|
|
42
73
|
|
|
43
74
|
```java
|
|
44
|
-
//
|
|
45
|
-
public sealed interface DomainEvent
|
|
75
|
+
// Events are immutable records with eventId and timestamp
|
|
76
|
+
public sealed interface DomainEvent
|
|
77
|
+
permits DemandCreated, DemandDecomposed, TaskCompleted {
|
|
46
78
|
String eventId();
|
|
47
79
|
Instant occurredAt();
|
|
48
80
|
String aggregateId();
|
|
49
81
|
}
|
|
50
82
|
|
|
51
|
-
// Eventos específicos
|
|
52
83
|
public record DemandCreated(
|
|
53
84
|
String eventId,
|
|
54
85
|
Instant occurredAt,
|
|
@@ -68,7 +99,7 @@ public record TaskCompleted(
|
|
|
68
99
|
) implements DomainEvent {}
|
|
69
100
|
```
|
|
70
101
|
|
|
71
|
-
|
|
102
|
+
### Step 4: Create Producer
|
|
72
103
|
|
|
73
104
|
```java
|
|
74
105
|
@Service
|
|
@@ -83,7 +114,8 @@ public class DemandEventProducer {
|
|
|
83
114
|
if (ex != null) {
|
|
84
115
|
log.error("Failed to publish event {}", event.eventId(), ex);
|
|
85
116
|
} else {
|
|
86
|
-
log.info("Published {} to partition {}",
|
|
117
|
+
log.info("Published {} to partition {}",
|
|
118
|
+
event.eventId(),
|
|
87
119
|
result.getRecordMetadata().partition());
|
|
88
120
|
}
|
|
89
121
|
});
|
|
@@ -91,7 +123,7 @@ public class DemandEventProducer {
|
|
|
91
123
|
}
|
|
92
124
|
```
|
|
93
125
|
|
|
94
|
-
|
|
126
|
+
### Step 5: Create Idempotent Consumer
|
|
95
127
|
|
|
96
128
|
```java
|
|
97
129
|
@Service
|
|
@@ -103,7 +135,7 @@ public class DemandEventConsumer {
|
|
|
103
135
|
|
|
104
136
|
@KafkaListener(topics = "demand-events", groupId = "agent-service")
|
|
105
137
|
public void onDemandEvent(DomainEvent event) {
|
|
106
|
-
//
|
|
138
|
+
// Idempotency: skip already processed events
|
|
107
139
|
if (processedEventRepo.existsById(event.eventId())) {
|
|
108
140
|
log.info("Event {} already processed, skipping", event.eventId());
|
|
109
141
|
return;
|
|
@@ -112,7 +144,7 @@ public class DemandEventConsumer {
|
|
|
112
144
|
switch (event) {
|
|
113
145
|
case DemandDecomposed e -> allocationService.allocateForDemand(e);
|
|
114
146
|
case DemandCreated e -> log.info("Demand created: {}", e.aggregateId());
|
|
115
|
-
default -> log.warn("Unknown event type: {}", event.getClass()
|
|
147
|
+
default -> log.warn("Unknown event type: {}", event.getClass());
|
|
116
148
|
}
|
|
117
149
|
|
|
118
150
|
processedEventRepo.save(new ProcessedEvent(event.eventId(), Instant.now()));
|
|
@@ -120,9 +152,10 @@ public class DemandEventConsumer {
|
|
|
120
152
|
}
|
|
121
153
|
```
|
|
122
154
|
|
|
123
|
-
|
|
155
|
+
### Step 6: Configure Dead Letter Queue
|
|
124
156
|
|
|
125
157
|
```yaml
|
|
158
|
+
# application.yml
|
|
126
159
|
spring:
|
|
127
160
|
cloud:
|
|
128
161
|
stream:
|
|
@@ -135,11 +168,71 @@ spring:
|
|
|
135
168
|
autoCommitOnError: false
|
|
136
169
|
```
|
|
137
170
|
|
|
138
|
-
|
|
171
|
+
### Step 7: Verify and Monitor
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# List topics
|
|
175
|
+
docker exec kafka kafka-topics --list --bootstrap-server localhost:29092
|
|
176
|
+
|
|
177
|
+
# Consume from a topic (for debugging)
|
|
178
|
+
docker exec kafka kafka-console-consumer \
|
|
179
|
+
--bootstrap-server localhost:29092 \
|
|
180
|
+
--topic demand-events \
|
|
181
|
+
--from-beginning
|
|
182
|
+
|
|
183
|
+
# Check consumer group lag
|
|
184
|
+
docker exec kafka kafka-consumer-groups \
|
|
185
|
+
--bootstrap-server localhost:29092 \
|
|
186
|
+
--group agent-service \
|
|
187
|
+
--describe
|
|
188
|
+
|
|
189
|
+
# Check DLQ for failed messages
|
|
190
|
+
docker exec kafka kafka-console-consumer \
|
|
191
|
+
--bootstrap-server localhost:29092 \
|
|
192
|
+
--topic demand-events-dlq \
|
|
193
|
+
--from-beginning
|
|
194
|
+
|
|
195
|
+
# Run tests
|
|
196
|
+
./mvnw test -Dtest="*EventProducer*,*EventConsumer*"
|
|
197
|
+
```
|
|
139
198
|
|
|
140
|
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
199
|
+
## Resources
|
|
200
|
+
- `references/kafka-patterns.md` - Kafka messaging patterns and best practices
|
|
201
|
+
- `references/event-schema.md` - Domain event schema conventions
|
|
202
|
+
|
|
203
|
+
## Examples
|
|
204
|
+
|
|
205
|
+
### Example 1: Add New Event Type
|
|
206
|
+
User asks: "Create a TaskCompleted event"
|
|
207
|
+
Response approach:
|
|
208
|
+
1. Create `TaskCompleted` record implementing `DomainEvent`
|
|
209
|
+
2. Add to sealed interface permits list
|
|
210
|
+
3. Publish from agent-service when task completes
|
|
211
|
+
4. Add consumer in demand-service to update demand status
|
|
212
|
+
5. Run `./mvnw test`
|
|
213
|
+
|
|
214
|
+
### Example 2: Debug Missing Events
|
|
215
|
+
User asks: "Consumers are not receiving events"
|
|
216
|
+
Response approach:
|
|
217
|
+
1. Check Kafka is running: `docker-compose logs kafka`
|
|
218
|
+
2. Verify topic exists: `kafka-topics --list`
|
|
219
|
+
3. Check consumer group: `kafka-consumer-groups --describe`
|
|
220
|
+
4. Produce test message: `kafka-console-producer`
|
|
221
|
+
5. Check DLQ for errors
|
|
222
|
+
|
|
223
|
+
### Example 3: Handle Duplicate Events
|
|
224
|
+
User asks: "Consumer is processing the same event twice"
|
|
225
|
+
Response approach:
|
|
226
|
+
1. Add `ProcessedEvent` entity and repository
|
|
227
|
+
2. Check `processedEventRepo.existsById(eventId)` before processing
|
|
228
|
+
3. Save event ID after successful processing
|
|
229
|
+
4. Test with duplicate messages
|
|
230
|
+
|
|
231
|
+
## Notes
|
|
232
|
+
- One topic per bounded context (not per entity)
|
|
233
|
+
- Consumers MUST be idempotent (same event can arrive 2x)
|
|
234
|
+
- DLQ for events that failed processing
|
|
235
|
+
- Events are immutable (Java records)
|
|
236
|
+
- Always include `eventId` and `occurredAt` in every event
|
|
237
|
+
- Consumer group = service name
|
|
238
|
+
- Use `aggregateId` as Kafka message key for ordering
|
package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/references/kafka-events.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Kafka Event Design Patterns
|
|
2
|
+
|
|
3
|
+
## Event Structure
|
|
4
|
+
```java
|
|
5
|
+
public sealed interface DomainEvent {
|
|
6
|
+
String eventId(); // Unique ID for idempotency
|
|
7
|
+
Instant occurredAt(); // When it happened
|
|
8
|
+
String aggregateId(); // For partitioning
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Topic Naming
|
|
13
|
+
- One topic per bounded context
|
|
14
|
+
- Format: `<context>-events` (e.g., `demand-events`, `agent-events`)
|
|
15
|
+
- DLQ: `<topic>-dlq` (e.g., `demand-events-dlq`)
|
|
16
|
+
|
|
17
|
+
## Consumer Group Naming
|
|
18
|
+
- Group = service name (e.g., `agent-service`)
|
|
19
|
+
- Each service gets its own group for independent consumption
|
|
20
|
+
|
|
21
|
+
## Idempotency Pattern
|
|
22
|
+
```java
|
|
23
|
+
if (processedEventRepo.existsById(event.eventId())) return;
|
|
24
|
+
// process event
|
|
25
|
+
processedEventRepo.save(new ProcessedEvent(event.eventId(), Instant.now()));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Error Handling
|
|
29
|
+
1. Retry (automatic, configurable)
|
|
30
|
+
2. Dead Letter Queue (after max retries)
|
|
31
|
+
3. Monitor DLQ for failed events
|
|
32
|
+
4. Manual replay from DLQ after fixing
|
|
33
|
+
|
|
34
|
+
## Monitoring Commands
|
|
35
|
+
```bash
|
|
36
|
+
kafka-topics --list --bootstrap-server localhost:9092
|
|
37
|
+
kafka-consumer-groups --describe --group <group> --bootstrap-server localhost:9092
|
|
38
|
+
kafka-console-consumer --topic <topic> --from-beginning --bootstrap-server localhost:9092
|
|
39
|
+
```
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: jhipster-registry
|
|
3
|
-
description:
|
|
3
|
+
description: Configure service discovery with Consul or Eureka and centralized configuration. Use when registering services, configuring discovery, centralizing configuration, or troubleshooting service registration.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# JHipster Registry / Service Discovery
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Configure and manage service discovery using Consul (recommended) for automatic service registration, health checks, and centralized configuration.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
- When setting up service discovery for new microservices
|
|
14
|
+
- When configuring centralized application properties
|
|
15
|
+
- When troubleshooting service registration issues
|
|
16
|
+
- When setting up Feign clients for inter-service communication
|
|
17
|
+
- When configuring health checks
|
|
18
|
+
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Set up Consul with Docker Compose
|
|
21
|
+
2. Configure service registration in each microservice
|
|
22
|
+
3. Store shared configuration in Consul KV
|
|
23
|
+
4. Set up Feign clients with service discovery
|
|
24
|
+
5. Monitor service health
|
|
25
|
+
|
|
26
|
+
## Multi-Step Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Start Consul with Docker Compose
|
|
9
29
|
|
|
10
|
-
### Docker Compose
|
|
11
30
|
```yaml
|
|
31
|
+
# docker-compose/consul.yml
|
|
12
32
|
consul:
|
|
13
33
|
image: consul:1.15
|
|
14
34
|
ports:
|
|
@@ -16,9 +36,21 @@ consul:
|
|
|
16
36
|
command: agent -server -bootstrap -ui -client=0.0.0.0
|
|
17
37
|
```
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
```bash
|
|
40
|
+
docker-compose -f docker-compose/consul.yml up -d
|
|
41
|
+
|
|
42
|
+
# Verify Consul is running
|
|
43
|
+
curl http://localhost:8500/v1/status/leader
|
|
44
|
+
|
|
45
|
+
# Open Consul UI
|
|
46
|
+
# http://localhost:8500
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Step 2: Configure Service Registration
|
|
50
|
+
|
|
51
|
+
Add to each microservice's `application.yml`:
|
|
52
|
+
|
|
20
53
|
```yaml
|
|
21
|
-
# application.yml de cada microsserviço
|
|
22
54
|
spring:
|
|
23
55
|
cloud:
|
|
24
56
|
consul:
|
|
@@ -35,12 +67,10 @@ spring:
|
|
|
35
67
|
default-context: application
|
|
36
68
|
```
|
|
37
69
|
|
|
38
|
-
###
|
|
39
|
-
|
|
40
|
-
Colocar configs compartilhadas no Consul KV store:
|
|
70
|
+
### Step 3: Store Shared Configuration in Consul KV
|
|
41
71
|
|
|
42
72
|
```yaml
|
|
43
|
-
# config/application/data
|
|
73
|
+
# config/application/data in Consul KV store
|
|
44
74
|
spring:
|
|
45
75
|
datasource:
|
|
46
76
|
type: com.zaxxer.hikari.HikariDataSource
|
|
@@ -54,30 +84,69 @@ management:
|
|
|
54
84
|
include: health,info,prometheus
|
|
55
85
|
```
|
|
56
86
|
|
|
57
|
-
|
|
87
|
+
```bash
|
|
88
|
+
# Add config to Consul KV via CLI
|
|
89
|
+
consul kv put config/application/data @shared-config.yml
|
|
90
|
+
|
|
91
|
+
# Or via HTTP API
|
|
92
|
+
curl -X PUT -d @shared-config.yml http://localhost:8500/v1/kv/config/application/data
|
|
93
|
+
```
|
|
58
94
|
|
|
59
|
-
|
|
95
|
+
### Step 4: Set Up Feign Clients
|
|
60
96
|
|
|
61
97
|
```java
|
|
62
|
-
// Feign Client
|
|
98
|
+
// Feign Client uses service discovery automatically
|
|
63
99
|
@FeignClient(name = "agent-service")
|
|
64
100
|
public interface AgentServiceClient {
|
|
65
101
|
@GetMapping("/api/agents/{id}")
|
|
66
102
|
AgentDTO getAgent(@PathVariable Long id);
|
|
67
103
|
}
|
|
68
|
-
|
|
69
|
-
// O nome "agent-service" é resolvido via Consul/Eureka
|
|
104
|
+
// The name "agent-service" is resolved via Consul
|
|
70
105
|
```
|
|
71
106
|
|
|
72
|
-
|
|
107
|
+
### Step 5: Verify Service Registration
|
|
73
108
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
109
|
+
```bash
|
|
110
|
+
# List registered services
|
|
111
|
+
curl http://localhost:8500/v1/catalog/services
|
|
77
112
|
|
|
78
|
-
|
|
113
|
+
# Check specific service instances
|
|
114
|
+
curl http://localhost:8500/v1/health/service/demand-service
|
|
115
|
+
|
|
116
|
+
# Check service health in Consul UI
|
|
117
|
+
# http://localhost:8500/ui/dc1/services
|
|
118
|
+
```
|
|
79
119
|
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
## Resources
|
|
121
|
+
- `references/consul-config.md` - Consul configuration and KV store reference
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
### Example 1: Register a New Service
|
|
125
|
+
User asks: "Register the new bundle-service with Consul"
|
|
126
|
+
Response approach:
|
|
127
|
+
1. Add Consul discovery config to `application.yml`
|
|
128
|
+
2. Set `spring.application.name: bundle-service`
|
|
129
|
+
3. Configure health check path
|
|
130
|
+
4. Start the service and verify in Consul UI
|
|
131
|
+
|
|
132
|
+
### Example 2: Add Shared Configuration
|
|
133
|
+
User asks: "Share database pool settings across all services"
|
|
134
|
+
Response approach:
|
|
135
|
+
1. Write shared config YAML
|
|
136
|
+
2. Store in Consul KV under `config/application/data`
|
|
137
|
+
3. Verify services pick up the configuration on restart
|
|
138
|
+
|
|
139
|
+
### Example 3: Debug Service Not Found
|
|
140
|
+
User asks: "Feign client cannot find agent-service"
|
|
141
|
+
Response approach:
|
|
142
|
+
1. Check Consul UI for the service registration
|
|
143
|
+
2. Verify health check is passing: `curl http://localhost:8500/v1/health/service/agent-service`
|
|
144
|
+
3. Check `spring.cloud.consul` config in the failing service
|
|
145
|
+
4. Review service logs for registration errors
|
|
146
|
+
|
|
147
|
+
## Notes
|
|
148
|
+
- Every service MUST register with discovery
|
|
149
|
+
- Health check endpoint MUST respond in < 1s
|
|
150
|
+
- Use `instance-id` with random value for multiple instances
|
|
151
|
+
- Shared configs in Consul KV, service-specific in local `application.yml`
|
|
152
|
+
- Gateway stops routing to unhealthy instances automatically
|
package/templates/bundle-jhipster-microservices/skills/jhipster-registry/references/consul-config.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Consul Configuration Reference
|
|
2
|
+
|
|
3
|
+
## Service Registration
|
|
4
|
+
```yaml
|
|
5
|
+
spring:
|
|
6
|
+
cloud:
|
|
7
|
+
consul:
|
|
8
|
+
host: consul
|
|
9
|
+
port: 8500
|
|
10
|
+
discovery:
|
|
11
|
+
service-name: ${spring.application.name}
|
|
12
|
+
health-check-path: /management/health
|
|
13
|
+
health-check-interval: 15s
|
|
14
|
+
instance-id: ${spring.application.name}:${random.value}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Centralized Config
|
|
18
|
+
```yaml
|
|
19
|
+
spring:
|
|
20
|
+
cloud:
|
|
21
|
+
consul:
|
|
22
|
+
config:
|
|
23
|
+
enabled: true
|
|
24
|
+
format: yaml
|
|
25
|
+
default-context: application # Shared config key prefix
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## KV Store Paths
|
|
29
|
+
| Path | Scope |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `config/application/data` | Shared by all services |
|
|
32
|
+
| `config/demand-service/data` | Specific to demand-service |
|
|
33
|
+
| `config/agent-service/data` | Specific to agent-service |
|
|
34
|
+
|
|
35
|
+
## CLI Commands
|
|
36
|
+
```bash
|
|
37
|
+
# List services
|
|
38
|
+
consul catalog services
|
|
39
|
+
|
|
40
|
+
# Check service health
|
|
41
|
+
consul catalog nodes -service=demand-service
|
|
42
|
+
|
|
43
|
+
# Put KV data
|
|
44
|
+
consul kv put config/application/data @config.yml
|
|
45
|
+
|
|
46
|
+
# Get KV data
|
|
47
|
+
consul kv get config/application/data
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## HTTP API
|
|
51
|
+
```bash
|
|
52
|
+
# List services
|
|
53
|
+
curl http://localhost:8500/v1/catalog/services
|
|
54
|
+
|
|
55
|
+
# Service health
|
|
56
|
+
curl http://localhost:8500/v1/health/service/demand-service
|
|
57
|
+
|
|
58
|
+
# KV operations
|
|
59
|
+
curl -X PUT -d @config.yml http://localhost:8500/v1/kv/config/application/data
|
|
60
|
+
curl http://localhost:8500/v1/kv/config/application/data?raw
|
|
61
|
+
```
|