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.
What does acks = all (acks = -1) mean in Kafka producer settings?
Producer waits for acknowledgement from all in-sync replicas, ensuring no data loss.
What is the purpose of min.insync.replicas in Kafka?
Controls the minimum number of replicas that must acknowledge a write for it to be considered successful.
What is an Idempotent Producer in Kafka?
A producer that guarantees no duplicate messages on network errors.
What is the default compression type for Kafka producers?
none
What are the advantages of using compression in Kafka?
- Smaller producer request size
- Faster data transfer
- Better throughput
- Improved disk utilization
What are the disadvantages of using compression in Kafka?
- Producers must commit CPU cycles to compression
- Consumers must commit CPU cycles to decompression
What setting allows for increased batching in Kafka producers?
linger.ms.
Fill in the blank: The rule ‘same key goes to the same partition’ is true unless the number of ______ changes.
partitions.