Bird
0
0

Identify the error in this Kafka consumer code snippet that tries to send failed messages to a DLQ:

medium📝 Debug Q14 of 15
Kafka - Event-Driven Architecture
Identify the error in this Kafka consumer code snippet that tries to send failed messages to a DLQ:
try {
  process(record);
} catch (Exception e) {
  producer.send("dlq-topic", record.key(), record.value());
}
AThe catch block should rethrow the exception
BThe producer.send method is missing a ProducerRecord object
CThe process method should not be inside try-catch
DThe record.key() cannot be used as a message key
Step-by-Step Solution
Solution:
  1. Step 1: Check the producer.send method usage

    The producer.send method requires a ProducerRecord object, not separate parameters.
  2. Step 2: Identify correct usage

    The correct call is producer.send(new ProducerRecord<>("dlq-topic", record.key(), record.value()));
  3. Final Answer:

    The producer.send method is missing 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 and data as separate arguments to send
  • Ignoring exception handling best practices
  • Misusing record key as invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes