Skip to content

Commit 3ca9d86

Browse files
committed
Update setup doc with DLQ details
1 parent 43e3271 commit 3ca9d86

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

KAFKA_SETUP.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ docker exec -it kafka kafka-console-consumer --topic avscan.action.scan --from-b
106106
2. Register the handler in the KafkaModule providers array
107107
3. The handler will automatically be registered and start consuming messages
108108

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+
109139
### Monitoring and Debugging
110140

111141
- **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`:
121151
- `KAFKA_GROUP_ID`: Consumer group ID
122152
- `KAFKA_SSL_ENABLED`: Enable SSL encryption
123153
- 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
124158

125159
## Troubleshooting
126160

@@ -129,6 +163,7 @@ All Kafka-related environment variables are documented in `.env.sample`:
129163
1. **Connection Refused**: Ensure Kafka is running with `docker compose -f docker-compose.kafka.yml ps`
130164
2. **Topic Not Found**: Topics are auto-created by default, or create manually using Kafka UI
131165
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
132167

133168
### Cleanup
134169

@@ -145,5 +180,9 @@ docker compose -f docker-compose.kafka.yml down -v
145180
- Configure SSL/TLS and SASL authentication for production environments
146181
- Set appropriate retention policies for topics
147182
- 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

Comments
 (0)