Bird
0
0

Given this Kafka Streams code snippet, what happens when a bad record causes an exception?

medium📝 Predict Output Q13 of 15
Kafka - Advanced Stream Processing
Given this Kafka Streams code snippet, what happens when a bad record causes an exception?
streams.foreach((key, value) -> {
  try {
    process(value);
  } catch (Exception e) {
    deadLetterTopic.send(key, value);
  }
});
AThe exception crashes the whole application
BThe stream stops processing immediately
CThe bad record is ignored and lost
DThe bad record is sent to a dead-letter topic for later review
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try-catch block in code

    The code tries to process each record; if an exception occurs, it catches it.
  2. Step 2: Check catch block action

    In catch, the bad record is sent to deadLetterTopic for later review.
  3. Final Answer:

    The bad record is sent to a dead-letter topic for later review -> Option D
  4. Quick Check:

    Exception caught = send to dead-letter topic [OK]
Quick Trick: Catch exceptions and send bad data to dead-letter topic [OK]
Common Mistakes:
MISTAKES
  • Assuming stream stops on exception
  • Thinking bad data is lost without handling
  • Believing exception crashes app without catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes