Bird
0
0

Consider this Kafka consumer snippet:

medium📝 Predict Output Q4 of 15
Kafka - Event-Driven Architecture
Consider this Kafka consumer snippet:
try {
  handle(record);
} catch (Exception e) {
  producer.send(new ProducerRecord<>("dlq-topic", record.key(), record.value()));
}
What is the effect if handle(record) throws an exception?
AThe message is sent to the "dlq-topic" for later inspection
BThe consumer retries processing the message indefinitely
CThe message is discarded without notification
DThe consumer shuts down immediately
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try-catch block

    If handle(record) throws, the catch block executes.
  2. Step 2: Check catch block action

    The catch block sends the failed message to the "dlq-topic" using the producer.
  3. Final Answer:

    The message is sent to the "dlq-topic" for later inspection -> Option A
  4. Quick Check:

    Exception triggers DLQ send [OK]
Quick Trick: Exception triggers sending message to DLQ topic [OK]
Common Mistakes:
MISTAKES
  • Assuming automatic retries without explicit code
  • Thinking the message is discarded silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes