Producer and Consumer details Flashcards
What are the steps to create a producer in Java?
- Create producer properties
- Create the producer
- Send data
- Flush and close the producer
The flush method is called automatically when closing the producer.
What properties are set for a Kafka producer?
- key.serializer
- value.serializer
Both are set using StringSerializer.class.getName()
What does the producer.send() method do?
Sends data asynchronously to the Kafka topic.
What is the purpose of the producer.flush() method?
To send all data and block until done.
What is the default batch size for Kafka?
16kB.
True or False: If the same key is sent to Kafka, it will always go to the same partition.
True.
What are the initial steps to consume messages from Kafka with Java?
- Connect to Kafka
- Create consumer configs
- Create a consumer
- Subscribe to a topic
- Poll for data
What are the key properties set for a Kafka consumer?
- key.deserializer
- value.deserializer
- group.id
- auto.offset.reset
Example values include StringDeserializer.class.getName() and ‘earliest’ for auto.offset.reset.
What are the three values for auto.offset.reset?
- none
- earliest
- latest
What happens during a partition rebalance in Kafka?
Partitions are moved between consumers when a consumer leaves or joins a group.
What is Eager Rebalance in Kafka?
All consumers stop polling and rejoin the group for new partition assignments.
What is Cooperative Rebalance in Kafka?
Reassigns a small subset of partitions while allowing other consumers to continue processing.
What are the strategies for partition assignment in Kafka?
- RangeAssignor
- RoundRobin
- StickyAssignor
- CooperativeStickyAssignor
What does acks = 0 mean in Kafka producer settings?
Producer won’t wait for acknowledgement, leading to possible data loss.
What does acks = 1 mean in Kafka producer settings?
Producer waits for leader acknowledgement, allowing for limited data loss.