Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a stream builder instance.
Kafka
StreamsBuilder builder = new [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using KafkaStreams instead of StreamsBuilder.
Using Topology directly without builder.
✗ Incorrect
StreamsBuilder is used to create the stream processing topology.
2fill in blank
mediumComplete the code to define a source stream from a topic named 'input-topic'.
Kafka
KStream<String, String> source = builder.stream([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the topic name.
Using the wrong topic name.
✗ Incorrect
The stream method requires the topic name as a string literal.
3fill in blank
hardFix the error in the code to send the processed stream to an output topic.
Kafka
processedStream.to([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable name without quotes.
Passing the stream variable itself.
✗ Incorrect
The to() method requires the topic name as a quoted string.
4fill in blank
hardFill both blanks to build and start the Kafka Streams application.
Kafka
Topology topology = builder.[1](); KafkaStreams streams = new KafkaStreams(topology, [2]); streams.start();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() instead of build() on builder.
Passing config instead of props.
✗ Incorrect
Use build() to create the topology and pass the properties object to KafkaStreams.
5fill in blank
hardFill all three blanks to create a stream, filter messages with value length > 5, and send to 'filtered-topic'.
Kafka
KStream<String, String> stream = builder.stream([1]); KStream<String, String> filtered = stream.filter((key, value) -> value.[2]() > [3]); filtered.to("filtered-topic");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size() instead of length() for strings.
Not quoting the topic name.
✗ Incorrect
We read from "input-topic", use length() to get string length, and filter values longer than 5.