@@ -15,6 +15,7 @@ docker compose -f docker-compose.kafka.yml ps
15
15
```
16
16
17
17
This will start:
18
+
18
19
- ** Zookeeper** on port 2181
19
20
- ** Kafka** on port 9092
20
21
- ** Kafka UI** on port 8080 (web interface)
@@ -40,6 +41,7 @@ pnpm run start:dev
40
41
```
41
42
42
43
The application will automatically:
44
+
43
45
- Connect to Kafka on startup
44
46
- Subscribe to registered topics
45
47
- Start consuming messages
@@ -80,9 +82,13 @@ docker exec -it kafka kafka-console-consumer --topic avscan.action.scan --from-b
80
82
### Adding New Event Handlers
81
83
82
84
1 . Create a new handler class extending ` BaseEventHandler ` :
85
+
83
86
``` typescript
84
87
@Injectable ()
85
- export class MyCustomHandler extends BaseEventHandler implements OnModuleInit {
88
+ export class MyCustomHandler
89
+ extends BaseEventHandler
90
+ implements OnModuleInit
91
+ {
86
92
private readonly topic = ' my.custom.topic' ;
87
93
88
94
constructor (private readonly handlerRegistry : KafkaHandlerRegistry ) {
@@ -103,14 +109,15 @@ docker exec -it kafka kafka-console-consumer --topic avscan.action.scan --from-b
103
109
}
104
110
```
105
111
106
- 2 . Register the handler in the KafkaModule providers array
107
- 3 . The handler will automatically be registered and start consuming messages
112
+ 2 . Register the handler in the ` src/shared/modules/kafka/handlers/registered-handlers.config.ts ` config handlers array.
113
+ 3 . The handler will automatically be registered and start consuming messages.
108
114
109
115
### Dead Letter Queue (DLQ) Support
110
116
111
117
The application includes a robust Dead Letter Queue implementation for handling message processing failures:
112
118
113
119
1 . ** Configuration** :
120
+
114
121
```
115
122
# DLQ Configuration in .env
116
123
KAFKA_DLQ_ENABLED=true
@@ -119,11 +126,13 @@ The application includes a robust Dead Letter Queue implementation for handling
119
126
```
120
127
121
128
2 . ** Retry Mechanism** :
129
+
122
130
- Failed messages are automatically retried up to the configured maximum number of retries
123
131
- Retry count is tracked per message using a unique key based on topic, partition, and offset
124
132
- Exponential backoff is applied between retries
125
133
126
134
3 . ** DLQ Processing** :
135
+
127
136
- After exhausting retries, messages are sent to a DLQ topic (original topic name + configured suffix)
128
137
- DLQ messages include:
129
138
- Original message content
@@ -133,6 +142,7 @@ The application includes a robust Dead Letter Queue implementation for handling
133
142
- Original message headers
134
143
135
144
4 . ** Monitoring DLQ** :
145
+
136
146
- Use Kafka UI to monitor DLQ topics (they follow the pattern ` <original-topic>.dlq ` )
137
147
- Check application logs for messages with "Message sent to DLQ" or "Failed to send message to DLQ"
138
148
@@ -185,4 +195,4 @@ docker compose -f docker-compose.kafka.yml down -v
185
195
- Messages in DLQ topics
186
196
- High retry rates
187
197
- Consumer failures
188
- - Implement a process for reviewing and potentially reprocessing DLQ messages
198
+ - Implement a process for reviewing and potentially reprocessing DLQ messages
0 commit comments