0
0
Kafkadevops~5 mins

Subscribing to topics in Kafka - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean to subscribe to a topic in Kafka?
Subscribing to a topic means telling the Kafka consumer which topics it should listen to for new messages. The consumer will then receive messages from those topics.
Click to reveal answer
beginner
How do you subscribe to multiple topics in Kafka using the consumer API?
You provide a list of topic names to the consumer's subscribe method, like consumer.subscribe(Arrays.asList("topic1", "topic2")). This makes the consumer listen to all listed topics.
Click to reveal answer
intermediate
What is the difference between subscribing to topics and assigning partitions in Kafka?
Subscribing lets Kafka manage which partitions the consumer reads from automatically. Assigning partitions means you manually tell the consumer exactly which partitions to read, giving more control but requiring manual management.
Click to reveal answer
intermediate
What happens if a consumer subscribes to a topic that does not exist yet?
The consumer will keep trying to find the topic. If the topic is created later, the consumer will start receiving messages from it. This allows dynamic topic creation.
Click to reveal answer
beginner
Why is it important to call consumer.poll() after subscribing to topics?
Calling consumer.poll() triggers the consumer to fetch messages from the subscribed topics. Without polling, the consumer won't receive any messages.
Click to reveal answer
What method is used to subscribe a Kafka consumer to topics?
Alisten()
Bassign()
Csubscribe()
Dconnect()
If you want Kafka to automatically manage partition assignment, you should:
AUse subscribe() with topic names
BUse assign() with partitions
CManually poll each partition
DCreate topics manually
What happens if you subscribe to a topic that does not exist yet?
AConsumer throws an error immediately
BConsumer subscribes to a random topic
CConsumer ignores the topic
DConsumer waits and starts receiving when topic is created
Which method must be called regularly to receive messages after subscribing?
Aconnect()
Bpoll()
Csubscribe()
Dcommit()
To listen to multiple topics, you should:
APass a list of topic names to subscribe()
BCall subscribe() multiple times
CUse assign() with multiple partitions
DCreate multiple consumers
Explain how subscribing to topics works in Kafka and why it is useful.
Think about how the consumer knows what to listen to.
You got /4 concepts.
    Describe the difference between subscribing to topics and assigning partitions in Kafka.
    Consider who manages the partitions in each case.
    You got /4 concepts.