Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add error handler for producer when using spring Kafka

Tags:

spring-kafka

How to add error handler for producer when using spring Kafka? I know how to add error handler for consumer but I am not sure about producer.

like image 911
FeeLGooD Avatar asked Oct 23 '25 22:10

FeeLGooD


1 Answers

See KafkaTemplate:

/**
 * Set a {@link ProducerListener} which will be invoked when Kafka acknowledges
 * a send operation. By default a {@link LoggingProducerListener} is configured
 * which logs errors only.
 * @param producerListener the listener; may be {@code null}.
 */
public void setProducerListener(ProducerListener<K, V> producerListener) {
    this.producerListener = producerListener;
}

And that one has this:

/**
 * Invoked after an attempt to send a message has failed.
 * @param topic the destination topic
 * @param partition the destination partition (could be null)
 * @param key the key of the outbound message
 * @param value the payload of the outbound message
 * @param exception the exception thrown
 */
void onError(String topic, Integer partition, K key, V value, Exception exception);
like image 145
Artem Bilan Avatar answered Oct 26 '25 02:10

Artem Bilan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!