0
0
Kafkadevops~10 mins

Consumer group concept 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 set the consumer group ID in Kafka consumer configuration.

Kafka
props.put("group.id", [1]);
Drag options to blanks, or click blank then click option'
A"my-group"
B"partition-0"
C"topic-name"
D"localhost"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the topic name instead of the group ID.
Using server address instead of group ID.
2fill in blank
medium

Complete the code to subscribe the consumer to a topic named "orders".

Kafka
consumer.subscribe(Collections.[1]("orders"));
Drag options to blanks, or click blank then click option'
AasList
BlistOf
CsingletonList
DemptyList
Attempts:
3 left
💡 Hint
Common Mistakes
Using emptyList which subscribes to no topics.
Using listOf which is not a Java Collections method.
3fill in blank
hard

Fix the error in the code to poll messages from Kafka consumer with a timeout of 100 milliseconds.

Kafka
ConsumerRecords<String, String> records = consumer.poll(Duration.[1](100));
Drag options to blanks, or click blank then click option'
AofMillis
BofMinutes
CofSeconds
DofNanos
Attempts:
3 left
💡 Hint
Common Mistakes
Using ofSeconds which would mean 100 seconds.
Using ofMinutes which is too long.
4fill in blank
hard

Fill both blanks to create a map of topic partitions to offsets for committing offsets manually.

Kafka
Map<TopicPartition, OffsetAndMetadata> offsets = Map.of(new TopicPartition("orders", [1]), new OffsetAndMetadata([2]));
Drag options to blanks, or click blank then click option'
A0
B15
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using an offset smaller than the last consumed offset.
Using a partition number that does not exist.
5fill in blank
hard

Fill all three blanks to create a consumer configuration with bootstrap servers, group ID, and auto offset reset policy.

Kafka
props.put("bootstrap.servers", [1]);
props.put("group.id", [2]);
props.put("auto.offset.reset", [3]);
Drag options to blanks, or click blank then click option'
A"localhost:9092"
B"my-group"
C"earliest"
D"latest"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up bootstrap servers and group ID values.
Using an invalid auto offset reset value.