K- outgoing record key type
V- outgoing record value type
public interface Sender<K,V>
|Modifier and Type||Method and Description|
Closes this sender and the underlying Kafka producer and releases all resources allocated to it.
Creates a Kafka sender that appends records to Kafka topic partitions.
Invokes the specified function on the Kafka
Sends a sequence of producer records to Kafka.
Sends a sequence of records to Kafka and returns a
static <K,V> Sender<K,V> create(SenderOptions<K,V> options)
options- Configuration options of this sender. Changes made to the options after the sender is created will not be used by the sender.
<T> Flux<SenderResult<T>> send(Publisher<SenderRecord<K,V,T>> records, boolean delayError)
Fluxof response record metadata including partition and offset of each send request. Ordering of responses is guaranteed for partitions, but responses from different partitions may be interleaved in a different order from the requests. Additional correlation metadata may be passed through in the
SenderRecordthat is not sent to Kafka, but is included in the response
Fluxto enable matching responses to requests.
Results are published when the send is acknowledged based on the acknowledgement mode
configured using the option
ProducerConfig.ACKS_CONFIG. If acks=0, records are acknowledged
after the requests are buffered without waiting for any server acknowledgements. In this case the
requests are not retried and the offset returned in
SenderResult will be -1. For other ack
modes, requests are retried up to the configured
ProducerConfig.RETRIES_CONFIG times. If
the request does not succeed after these attempts, the request fails and an exception indicating
the reason for failure is returned in
source = Flux.range(1, count) .map(i -> SenderRecord.create(new ProducerRecord<>(topic, key(i), message(i)), i)); sender.send(source, true) .doOnNext(r -> System.out.println("Message #" + r.correlationMetadata() + " metadata=" + r.recordMetadata()));
records- Outbound records along with additional correlation metadata to be included in response
delayError- If false, send terminates when a response indicates failure, otherwise send is attempted for all records
Monois failed immediately if a record cannot be delivered to Kafka after the configured number of retries in
records- Outbound producer records
Producerassociated with this Sender. The function is invoked when the returned
Monois subscribed to.
Functions that are directly supported on the reactive
sender.doOnProducer(producer -> producer.partitionsFor(topic)) .doOnSuccess(partitions -> System.out.println("Partitions " + partitions));
Senderinterface (eg. send) should not be invoked from
function. The methods supported by
function- A function that takes Kafka Producer as parameter