RocketMQ事务消息Demo

pom依赖:

org.apache.rocketmq rocketmq-client 4.7.0

示例代码:

TransactionMQProducer producer =new TransactionMQProducer();

producer.setNamesrvAddr("xx:9876");

producer.setProducerGroup("xx");

producer.setTransactionListener(new TransactionListener() {

@Override

        public LocalTransactionState executeLocalTransaction(Message msg,Object arg) {

return LocalTransactionState.COMMIT_MESSAGE;

}

@Override

        public LocalTransactionState checkLocalTransaction(MessageExt msg) {

return LocalTransactionState.COMMIT_MESSAGE;

}

});

producer.start();

        TransactionSendResult transactionSendResult =producer.sendMessageInTransaction(new Message("aa","aa".getBytes(StandardCharsets.UTF_8)),"");

}

你可能感兴趣的:(RocketMQ事务消息Demo)