如何在使用spring Kafka时为生产者添加错误处理程序?我知道如何为消费者添加错误处理程序,但我不确定生产者。
答案 0 :(得分:1)
请参阅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;
}
那个人有这个:
/**
* 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);