KafkaTopicProducer

class KafkaTopicProducer(producer: Producer<String, ByteArray>, dispatcher: CoroutineDispatcher = VirtualThreads.dispatcher) : TopicProducer, AutoCloseable

The TopicProducer over a Kafka producer: made by create from KafkaOptions, an idempotent producer with acks=all.

send hands every message to the producer in order, on a virtual thread since a send may block while the producer fetches metadata or its buffer is full, then suspends until the broker acknowledged each one; it throws the first failure, Kafka being unreachable or refusing a record for good as the SPI's typed failure (KafkaFailures). A message's partition is the one it names (TopicMessage.partition), else its key's (the producer's default partitioner), so the messages of an aggregate keep their order in one partition; the idempotent producer keeps that order through its own retries.

close flushes what is in flight and closes the producer.

Constructors

Link copied to clipboard
constructor(producer: Producer<String, ByteArray>, dispatcher: CoroutineDispatcher = VirtualThreads.dispatcher)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun send(topic: String, messages: List<TopicMessage>)