使用Spring Kafka时,如何为生产者添加错误处理程序



使用Spring Kafka时如何为生产者添加错误处理程序?我知道如何为消费者添加错误处理程序,但我不确定生产者。

请参阅 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);

最新更新