Bird
0
0

Examine this Kafka consumer code snippet:

medium📝 Debug Q6 of 15
Kafka - Event-Driven Architecture
Examine this Kafka consumer code snippet:
try {
  process(record);
} catch (Exception e) {
  producer.send("dlq-topic", record.key(), record.value());
}
What is the issue with this code regarding sending messages to the DLQ?
AThe catch block does not handle the exception properly and will crash the consumer
BThe producer.send method is called with incorrect parameters; it requires a ProducerRecord object
CThe DLQ topic name is invalid and will cause a runtime error
DThe code does not commit offsets after sending to DLQ
Step-by-Step Solution
Solution:
  1. Step 1: Review producer.send usage

    The producer.send method expects a ProducerRecord object, not separate parameters.
  2. Step 2: Identify the error

    Passing topic, key, and value as separate arguments is invalid and will cause a compilation or runtime error.
  3. Final Answer:

    The producer.send method is called with incorrect parameters; it requires a ProducerRecord object -> Option B
  4. Quick Check:

    producer.send needs ProducerRecord object [OK]
Quick Trick: producer.send requires ProducerRecord, not separate args [OK]
Common Mistakes:
MISTAKES
  • Passing topic, key, value directly to producer.send
  • Ignoring offset commits after DLQ send

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes