0
0
Kafkadevops~10 mins

Group coordinator 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 Kafka consumer with a group coordinator.

Kafka
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", [1]);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
Drag options to blanks, or click blank then click option'
A"my-group"
B"localhost"
C"consumer"
D"topic1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the broker address instead of the group id
Using the topic name as group id
Leaving group.id empty
2fill in blank
medium

Complete the code to subscribe the consumer to a topic.

Kafka
consumer.[1](Collections.singletonList("my-topic"));
Drag options to blanks, or click blank then click option'
AcommitSync
Bassign
Csubscribe
Dpoll
Attempts:
3 left
💡 Hint
Common Mistakes
Using assign instead of subscribe
Calling poll before subscribing
Using commitSync to subscribe
3fill in blank
hard

Fix the error in the code to poll messages from the consumer.

Kafka
ConsumerRecords<String, String> records = consumer.[1](Duration.ofMillis(100));
for (ConsumerRecord<String, String> record : records) {
    System.out.println(record.value());
}
Drag options to blanks, or click blank then click option'
Aassign
Bsubscribe
CcommitSync
Dpoll
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe instead of poll to get messages
Calling commitSync before polling
Using assign instead of poll
4fill in blank
hard

Fill both blanks to commit offsets synchronously after processing.

Kafka
consumer.[1](Duration.ofMillis(100));
try {
    consumer.[2]();
} catch (Exception e) {
    e.printStackTrace();
}
Drag options to blanks, or click blank then click option'
AcommitSync
Bpoll
Cclose
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Committing before polling
Using close instead of commitSync
Not handling exceptions during commit
5fill in blank
hard

Fill all three blanks to create a consumer, subscribe, and poll messages.

Kafka
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", [1]);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.[2](Collections.singletonList("my-topic"));
ConsumerRecords<String, String> records = consumer.[3](Duration.ofMillis(100));
Drag options to blanks, or click blank then click option'
A"group1"
Bsubscribe
Cpoll
D"topic1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using topic name as group.id
Calling poll before subscribe
Using assign instead of subscribe