注:发消息的代码会被正常调用,但是消息会在事务提交之后发给消费者
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void sendMessage(Map map) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
kafkaTemplate.send(MessageConstants.OPEN_WDZ_ACCEPT_WORK_INFO, JSONObject.toJSONString(map));
}
});
}