比如这样子:
public class Test {
@
Transactional public void createOrder() {
execCreateOrder();
sendHalfMessage();
commitCreateOrder();
}
@
RocketMQTransactionListener static class OrderTransactionListenerImpl implements RocketMQLocalTransactionListener {
@
Autowired private OrderService orderService;
@
Override public RocketMQLocalTransactionState executeLocalTransaction(Message msg, Object arg) {
log.info("----executeLocalTransaction----{}", msg.getHeaders().get(RocketMQHeaders.TRANSACTION_ID, String.class));
return RocketMQLocalTransactionState.COMMIT;
}
@
Override public RocketMQLocalTransactionState checkLocalTransaction(Message msg) {
log.info("----checkLocalTransaction----{}", msg.getHeaders().get(RocketMQHeaders.TRANSACTION_ID, String.class));
String keys = msg.getHeaders().get(RocketMQHeaders.TRANSACTION_ID, String.class);
Order order = orderService.query(orderId);
if (null == order) {
return RocketMQLocalTransactionState.UNKNOWN;
}
return RocketMQLocalTransactionState.COMMIT;
}
}
}