Bird
0
0

What will be the output of this Kafka Streams code snippet?

medium📝 Predict Output Q4 of 15
Kafka - Advanced Stream Processing
What will be the output of this Kafka Streams code snippet?
StreamsBuilder builder = new StreamsBuilder();
KStream stream = builder.stream("input-topic");
KStream filtered = stream.filter((k, v) -> v.contains("error"));
filtered.to("error-topic");
// Assume input-topic has messages: {"1":"ok"}, {"2":"error found"}
// What messages appear in error-topic?
A{"1":"ok"}
B{"2":"error found"}
C{"1":"ok"}, {"2":"error found"}
D{} (empty)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the filter condition

    The filter keeps messages where value contains "error".
  2. Step 2: Check input messages against filter

    Message {"2":"error found"} contains "error", so it passes; {"1":"ok"} does not.
  3. Final Answer:

    {"2":"error found"} -> Option B
  4. Quick Check:

    Filter output = messages containing "error" [OK]
Quick Trick: Filter keeps only matching messages in output topic [OK]
Common Mistakes:
  • Assuming all messages pass filter
  • Confusing key and value in filter
  • Ignoring filter condition logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes