Как добавить обработчик ошибок для производителя при использовании Spring Kafka

Как добавить обработчик ошибок для производителя при использовании Spring Kafka? Я знаю, как добавить обработчик ошибок для потребителя, но не уверен насчет производителя.


person FeeLGooD    schedule 14.12.2017    source источник


Ответы (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);
person Artem Bilan    schedule 14.12.2017
comment
будет ли этот слушатель выполняться в случае неудачной сборки производителя kafka, например, неправильного пароля? java.security.UnrecoverableKeyException: Password verification failed - person Deadpool; 06.01.2021
comment
Я думаю так. мы действительно подключаемся от производителя к Kafka лениво, когда отправка уже выполнена. - person Artem Bilan; 07.01.2021