0
0
Kafkadevops~10 mins

Dead letter queue pattern in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Amain-topic
Bdead-letter-queue
Cretry-topic
Derror-topic
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.
2fill in blank
medium

Complete 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'
Adead-letter-queue
Bretry-topic
Cmain-topic
Dsuccess-topic
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.
3fill in blank
hard

Fix 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'
Adead-letter-queue
Bmain-topic
Cretry-topic
Derror-topic
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.
4fill in blank
hard

Fill 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'
Adead-letter-queue
BfailedMessage
Cmain-topic
DsuccessMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Sending success messages to the dead letter queue.
Using the main topic for failed messages.
5fill in blank
hard

Fill 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'
Acontains
Bdead-letter-queue
Cmain-topic
DstartsWith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startsWith' instead of 'contains' to check for errors.
Sending all messages to the dead letter queue.