springboot和kafka融合

springboot和kafka融合,发送消息如何进行确认回调

//自己定义一个sendMessage的util,然厚监听成功失败处理方式
ListenableFuture<SendResult<String, String>> listenableFuture = kafkaTemplate.send(topic, JSON.toJSONString(messages));
            SuccessCallback<SendResult<String, String>> successCallback = result -> {
               log.info("发送kafka消息成功,offset:{},content:{},result:{},ret:{}", result.getRecordMetadata().offset(), JSON.toJSONString(messages), JSON.toJSONString(result), ret);
            };
            FailureCallback failureCallback = ex -> {
                //失败业务逻辑
                log.error("发送kafka消息失败,messages:{},result:{}", messages, JSON.toJSONString(messages), ex);
            };
1 个赞

谢谢

ack确认,百度应该挺多的