0
0
Kafkadevops~10 mins

Rebalancing behavior 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 for Kafka consumer.

Kafka
props.put("group.id", [1]);
Drag options to blanks, or click blank then click option'
A"localhost"
B"topic-name"
C"kafka-server"
D"my-group"
Attempts:
3 left
💡 Hint
Common Mistakes
Using server or topic names instead of a group ID.
Leaving the group.id property unset.
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'
AemptyList
BsingletonList
Csingleton
DlistOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using emptyList which subscribes to no topics.
Using singleton which is not a method in Collections.
3fill in blank
hard

Fix the error in the rebalance listener method signature.

Kafka
consumer.subscribe(topics, new ConsumerRebalanceListener() {
    @Override
    public void [1](Collection<TopicPartition> partitions) {
        // handle partitions revoked
    }

    @Override
    public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
        // handle partitions assigned
    }
});
Drag options to blanks, or click blank then click option'
AonPartitionsRevoked
BonRebalance
CpartitionsRevoked
DpartitionsAssigned
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like partitionsRevoked or onRebalance.
Confusing assigned and revoked methods.
4fill in blank
hard

Fill both blanks to commit offsets synchronously after partitions are assigned.

Kafka
public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
    consumer.[1]();
    consumer.[2](offsets);
}
Drag options to blanks, or click blank then click option'
AcommitSync
BcommitAsync
Cseek
Dpoll
Attempts:
3 left
💡 Hint
Common Mistakes
Using poll instead of commit methods.
Calling seek instead of commit.
5fill in blank
hard

Fill all three blanks to implement a rebalance listener that commits offsets and seeks to correct positions.

Kafka
consumer.subscribe(topics, new ConsumerRebalanceListener() {
    @Override
    public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
        consumer.[1]();
    }

    @Override
    public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
        for (TopicPartition partition : partitions) {
            consumer.[2](partition, offsets.get(partition));
        }
        consumer.[3]();
    }
});
Drag options to blanks, or click blank then click option'
AcommitSync
Bseek
CcommitAsync
Dpoll
Attempts:
3 left
💡 Hint
Common Mistakes
Using poll instead of commit or seek.
Not committing offsets before rebalance.