Interface ProducerListener<K,V>
- Type Parameters:
K
- the key type.V
- the value type.
- All Known Implementing Classes:
CompositeProducerListener
,LoggingProducerListener
public interface ProducerListener<K,V>
Listener for handling outbound Kafka messages. Exactly one of its methods will be invoked, depending on whether
the write has been acknowledged or not.
Its main goal is to provide a stateless singleton delegate for
Callback
s,
which, in all but the most trivial cases, requires creating a separate instance per message.- Author:
- Marius Bogoevici, Gary Russell, Endika GutiƩrrez
- See Also:
-
Callback
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
onError
(org.apache.kafka.clients.producer.ProducerRecord<K, V> producerRecord, org.apache.kafka.clients.producer.RecordMetadata recordMetadata, Exception exception) Invoked after an attempt to send a message has failed.default void
onSuccess
(org.apache.kafka.clients.producer.ProducerRecord<K, V> producerRecord, org.apache.kafka.clients.producer.RecordMetadata recordMetadata) Invoked after the successful send of a message (that is, after it has been acknowledged by the broker).
-
Method Details
-
onSuccess
default void onSuccess(org.apache.kafka.clients.producer.ProducerRecord<K, V> producerRecord, org.apache.kafka.clients.producer.RecordMetadata recordMetadata) Invoked after the successful send of a message (that is, after it has been acknowledged by the broker).- Parameters:
producerRecord
- the actual sent recordrecordMetadata
- the result of the successful send operation
-
onError
default void onError(org.apache.kafka.clients.producer.ProducerRecord<K, V> producerRecord, @Nullable org.apache.kafka.clients.producer.RecordMetadata recordMetadata, Exception exception) Invoked after an attempt to send a message has failed.- Parameters:
producerRecord
- the failed recordrecordMetadata
- The metadata for the record that was sent (i.e. the partition and offset). If an error occurred, metadata will contain only valid topic and maybe the partition. If the partition is not provided in the ProducerRecord and an error occurs before partition is assigned, then the partition will be set to RecordMetadata.UNKNOWN_PARTITION.exception
- the exception thrown- Since:
- 2.6.2
-