springboot 整合kafka 消费异常 数据回滚

1.入口

@KafkaListener(topics = {"TRADE_SYNCHRONIZE_2200C"})
    public void TradeSynchronizeConsumer(ConsumerRecord data, Acknowledgment ack) {


        List list = JSONArray.parseArray(data.value(), CardTrade.class);
        try {

            receiveTradeDataFacade.icCardDataSave(list);
            ack.acknowledge();

        } catch (Exception e) {
            //另存备注处理或者重新生产 后者容易死循环
            ack.acknowledge();

        }
    }

2.消费异常数据库回滚

    @Transactional(rollbackFor = RollbackException.class)
    @Override
    public Object icCardDataSave(List list) throws BusinessException {
            //业务
        }

3.配置文件

kafka:
    consumer:
        //手动提交必须设置为false 要不不生效
        enable-auto-commit: false 
    listener:
      //手动提交模式
      ack-mode: manual

 

你可能感兴趣的:(spring,boot,springboot,整合kafka,消费异常,数据回滚)