How could I go to "@Override public void onFailure(Throwable ex) { ... }"?
It always go "@Override public void onSuccess(SendResult<String, KafkaPresponseDto> result) {...}.
I want to print log.error("Unable to send message=["+kafkaPgResponseDto.toString()+"] due to : " + ex.getMessage());
Please help...
ListenableFuture<SendResult<String, KafkaPgResponseDto>> future = pgResponseKafkaTemplate.send(kurlyTopicNamePgResponse, kafkaPgResponseDto);
future.addCallback(new ListenableFutureCallback<SendResult<String, KafkaPgResponseDto>>(){
@Override
public void onSuccess(SendResult<String, KafkaPgResponseDto> result) {
KafkaPgResponseDto kafkaPgResponseDto = result.getProducerRecord().value();
log.debug("Send message=["+kafkaPgResponseDto.toString()+"] with offset=["+result.getRecordMetadata().offset()+"]");
}
@Override
public void onFailure(Throwable ex) {
log.error("Unable to send message=["+kafkaPgResponseDto.toString()+"] due to : "+ex.getMessage());
kafkaTransactionService.failedProcessingKafkaHistorySave(orderNo, kurlyTopicNamePgResponse, gson.toJson(payload), ex.toString());
}
});
I believe there is no need in the real Kafka to test your functionality. Consider to use a
MockProducer
for injection into thatKafkaTemplate
and emulate an error for thatonFailure()
case: https://www.baeldung.com/kafka-mockproducer