@@ -106,6 +106,36 @@ docker exec -it kafka kafka-console-consumer --topic avscan.action.scan --from-b
106
106
2 . Register the handler in the KafkaModule providers array
107
107
3 . The handler will automatically be registered and start consuming messages
108
108
109
+ ### Dead Letter Queue (DLQ) Support
110
+
111
+ The application includes a robust Dead Letter Queue implementation for handling message processing failures:
112
+
113
+ 1 . ** Configuration** :
114
+ ```
115
+ # DLQ Configuration in .env
116
+ KAFKA_DLQ_ENABLED=true
117
+ KAFKA_DLQ_TOPIC_SUFFIX=.dlq
118
+ KAFKA_DLQ_MAX_RETRIES=3
119
+ ```
120
+
121
+ 2 . ** Retry Mechanism** :
122
+ - Failed messages are automatically retried up to the configured maximum number of retries
123
+ - Retry count is tracked per message using a unique key based on topic, partition, and offset
124
+ - Exponential backoff is applied between retries
125
+
126
+ 3 . ** DLQ Processing** :
127
+ - After exhausting retries, messages are sent to a DLQ topic (original topic name + configured suffix)
128
+ - DLQ messages include:
129
+ - Original message content
130
+ - Error information
131
+ - Original topic, partition, and offset
132
+ - Timestamp of failure
133
+ - Original message headers
134
+
135
+ 4 . ** Monitoring DLQ** :
136
+ - Use Kafka UI to monitor DLQ topics (they follow the pattern ` <original-topic>.dlq ` )
137
+ - Check application logs for messages with "Message sent to DLQ" or "Failed to send message to DLQ"
138
+
109
139
### Monitoring and Debugging
110
140
111
141
- ** Application Logs** : Check console output for Kafka connection status and message processing
@@ -121,6 +151,10 @@ All Kafka-related environment variables are documented in `.env.sample`:
121
151
- ` KAFKA_GROUP_ID ` : Consumer group ID
122
152
- ` KAFKA_SSL_ENABLED ` : Enable SSL encryption
123
153
- Connection timeouts and retry configurations
154
+ - ** DLQ Configuration** :
155
+ - ` KAFKA_DLQ_ENABLED ` : Enable/disable the Dead Letter Queue feature
156
+ - ` KAFKA_DLQ_TOPIC_SUFFIX ` : Suffix to append to original topic name for DLQ topics
157
+ - ` KAFKA_DLQ_MAX_RETRIES ` : Maximum number of retries before sending to DLQ
124
158
125
159
## Troubleshooting
126
160
@@ -129,6 +163,7 @@ All Kafka-related environment variables are documented in `.env.sample`:
129
163
1 . ** Connection Refused** : Ensure Kafka is running with ` docker compose -f docker-compose.kafka.yml ps `
130
164
2 . ** Topic Not Found** : Topics are auto-created by default, or create manually using Kafka UI
131
165
3 . ** Consumer Group Issues** : Check consumer group status in Kafka UI under "Consumers"
166
+ 4 . ** DLQ Topics Missing** : DLQ topics are created automatically when the first message is sent to them
132
167
133
168
### Cleanup
134
169
@@ -145,5 +180,9 @@ docker compose -f docker-compose.kafka.yml down -v
145
180
- Configure SSL/TLS and SASL authentication for production environments
146
181
- Set appropriate retention policies for topics
147
182
- Monitor consumer lag and processing metrics
148
- - Configure dead letter queues for failed messages
149
- - Set up proper alerting for consumer failures
183
+ - Ensure DLQ topics have appropriate retention policies (longer than source topics)
184
+ - Set up alerts for:
185
+ - Messages in DLQ topics
186
+ - High retry rates
187
+ - Consumer failures
188
+ - Implement a process for reviewing and potentially reprocessing DLQ messages
0 commit comments