0
0
Kafkadevops~10 mins

KStream and KTable concepts in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a KStream from the topic 'input-topic'.

Kafka
KStream<String, String> stream = builder.stream([1]);
Drag options to blanks, or click blank then click option'
Atopic("input-topic")
Binput-topic
Cstream("input-topic")
D"input-topic"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the topic name.
Passing a variable without quotes.
Using incorrect method names.
2fill in blank
medium

Complete the code to create a KTable from the topic 'users'.

Kafka
KTable<String, String> table = builder.table([1]);
Drag options to blanks, or click blank then click option'
Atopic("users")
Busers
C"users"
Dtable("users")
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the topic name without quotes.
Using incorrect method calls inside the argument.
3fill in blank
hard

Fix the error in the code to convert a KStream to a KTable.

Kafka
KTable<String, String> table = stream.[1]();
Drag options to blanks, or click blank then click option'
AtoStream
BtoTable
CtoKTable
DasTable
Attempts:
3 left
💡 Hint
Common Mistakes
Using toStream() which converts to a stream, not a table.
Using non-existent methods like toKTable() or asTable().
4fill in blank
hard

Fill both blanks to filter a KStream for values greater than 100 and map keys to uppercase.

Kafka
KStream<String, Integer> filtered = stream.filter((key, value) -> value [1] 100).mapKeys((key, value) -> key.[2]());
Drag options to blanks, or click blank then click option'
A>
B<
CtoUpperCase
DtoLowerCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than symbol instead of greater than.
Using toLowerCase() instead of toUpperCase().
5fill in blank
hard

Fill all three blanks to create a KTable from a topic, filter entries with values not null, and map values to their length.

Kafka
KTable<String, Integer> result = builder.table([1]).filter((key, value) -> value [2] null).mapValues(value -> value.[3]());
Drag options to blanks, or click blank then click option'
A"events"
B!=
Clength
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operator instead of not equal.
Forgetting quotes around the topic name.
Using incorrect method names for string length.