Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a message to the dead letter queue topic.
Kafka
producer.send("[1]", record);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Sending the message to the main topic instead of the dead letter queue.
Using a retry topic instead of the dead letter queue.
✗ Incorrect
The dead letter queue topic is where failed messages are sent, so the producer must send to 'dead-letter-queue'.
2fill in blank
mediumComplete the code to check if the message processing failed and send it to the dead letter queue.
Kafka
if (processingFailed) { producer.send("[1]", message); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Sending failed messages back to the main topic.
Sending failed messages to a retry topic instead of dead letter queue.
✗ Incorrect
When processing fails, the message should be sent to the dead letter queue topic.
3fill in blank
hardFix the error in the consumer code to consume messages from the dead letter queue topic.
Kafka
consumer.subscribe(Collections.singletonList("[1]"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Subscribing to the main topic instead of the dead letter queue.
Using a retry topic for dead letter messages.
✗ Incorrect
To consume dead letter messages, the consumer must subscribe to the 'dead-letter-queue' topic.
4fill in blank
hardFill both blanks to create a dead letter queue producer and send a failed message.
Kafka
KafkaProducer<String, String> producer = new KafkaProducer<>(props); producer.send(new ProducerRecord<String, String>("[1]", "[2]"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Sending success messages to the dead letter queue.
Using the main topic for failed messages.
✗ Incorrect
The producer sends the failed message to the 'dead-letter-queue' topic.
5fill in blank
hardFill all three blanks to filter messages and send only failed ones to the dead letter queue.
Kafka
for (var record : consumer.poll(Duration.ofMillis(100))) { if (record.value().[1]("error")) { producer.send(new ProducerRecord<>("[2]", record.value())); } else { producer.send(new ProducerRecord<>("[3]", record.value())); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startsWith' instead of 'contains' to check for errors.
Sending all messages to the dead letter queue.
✗ Incorrect
We check if the message contains 'error' to send it to the dead letter queue; otherwise, it goes to the main topic.