- partitionsFor(topic)
// transactional producer
- initTransaction() // uses config transactional.id
- beginTransaction()
- commitTransaction()
// also possible to make idempotent producer
- send(record)
- ProducerRecord(topic, [partition], [timestamp], [key], value, [headers])
- partition or hash of the key or round-robin will be used to decide partition
- sendOffsetsToTransaction(offsets, groupId)
- close()
- subscribe(topic) // auto group rebalancing partitions when adding/removing consumers (group.id needed)
- assign(partitions) // when you are interested in only some partitions (group.id not needed but better specify)
- seekToBeginning()
- seek(partition, offset)
- seekToEnd()
- poll(size) // read
- commitSync()
- commitAsync(offsets)
- close()
Happens because of:
-
Delay in the next poll (consumer is too slow in processing the current poll)
-
Rebalance is triggered
RebalanceListener.java
- Map<Topic<Partition, OffsetAndMetadata>> offsets;
- addOffset(topic, partition, offset)
- getCurrentOffsets()
- onPartitionsAssigned()
// used to commit current work (offset) before you lose partition,
// so another consumer can continue from there
- onPartitionsRevoked()
- allows parallel processing of a topic (splitting it on partitions for each consumer)
- automatically manages partition assignment when calling
subscribe(topic) + group.id
- if interested in only some partitions use custom producer with partitioner and consumer
assign()
- then you don't have auto rebalancing
- if interested in only some partitions use custom producer with partitioner and consumer
- detects entry / exit / failure of a consumer and perform partition rebalancing activity