Bird
Raised Fist0

Identify the error in this Kafka Streams topology code: StreamsBuilder builder = new StreamsBuilder(); KStream stream = builder.stream("input"); stream.filter((k,v) -> v.length() > 5); stream.to("output");

medium📝 Debug Q6 of Q15
Kafka - Streams
Identify the error in this Kafka Streams topology code: StreamsBuilder builder = new StreamsBuilder(); KStream stream = builder.stream("input"); stream.filter((k,v) -> v.length() > 5); stream.to("output");
AThe stream method is called with wrong topic name
BThe filtered stream is not assigned or used before sending to output
CThe filter lambda syntax is incorrect
Dto() method cannot be called on a KStream
Step-by-Step Solution
Solution:
  1. Step 1: Check filter usage

    Filter returns a new stream but result is not saved or used.
  2. Step 2: Check to() call

    to() is called on original stream, so filtering has no effect on output.
  3. Final Answer:

    The filtered stream is not assigned or used before sending to output -> Option B
  4. Quick Check:

    Filter result must be used before to() [OK]
Quick Trick: Assign filtered stream before to() [OK]
Common Mistakes:
MISTAKES
  • Ignoring that filter returns a new stream
  • Calling to() on unfiltered stream
  • Assuming filter modifies stream in place

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes