Close the producer.
Flushes any pending batches before closing. After closing, no more messages can be sent.
Flush all accumulated messages immediately.
Forces all pending batches to be sent. Resolves when all batched messages have been acknowledged (or rejected on failure).
Send messages to a topic.
Partitions messages using the configured partitioner, encodes them as record batches, and sends produce requests to the appropriate brokers.
The topic to send messages to.
The messages to send.
Produce results per partition.
Send consumer offsets to the transaction.
Atomically commits consumer offsets as part of the current transaction, enabling exactly-once consume-transform-produce patterns.
The offsets to commit.
The consumer group ID.
Send messages targeting a specific partition directly.
Bypasses the partitioner. The caller is responsible for choosing the correct partition index.
The topic and partition to send to.
The messages to send.
Produce result for the partition.
Kafka producer.
Sends messages to topic partitions via the Produce API. Handles partition assignment, record batch encoding, and routing to the correct broker.
Example