ActiveMQ有支持两种事务,
- JMS transactions - the commit() / rollback() methods on a Session (which is like doing commit() / rollback() on a JDBC connection)
- XA Transactions - where the XASession acts as an XAResource by communicating with the Message Broker, rather like a JDBC Connection takes place in an XA transaction by communicating with the database.
在支持事务的session中,producer发送message时在message中带有transaction ID。broker收到message后判断是否有transaction ID,如果有就把message保存在transaction store中,等待commit或者rollback消息。所以ActiveMq的事务是针对broker而不是producer的,不管session是否commit,broker都会收到message。
如果producer发送模式选择了persistent,那么message过期后会进入死亡队列。在message进入死亡队列之前,ActiveMQ会删除message中的transaction ID,这样过期的message就不在事务中了,不会保存在transaction store中,会直接进入死亡队列。具体删除transaction ID的地方是在
org.apache.activemq.util.BrokerSupport的doResend,将transaction ID保存在了originalTransactionID中,删除了transaction ID
public static void doResend(final ConnectionContext context, Message originalMessage, ActiveMQDestination deadLetterDestination, boolean copy) throws Exception { Message message = copy ? originalMessage.copy() : originalMessage; message.setOriginalDestination(message.getDestination()); message.setOriginalTransactionId(message.getTransactionId()); message.setDestination(deadLetterDestination); message.setTransactionId(null); message.setMemoryUsage(null); message.setRedeliveryCounter(0); boolean originalFlowControl = context.isProducerFlowControl(); try { context.setProducerFlowControl(false); ProducerInfo info = new ProducerInfo(); ProducerState state = new ProducerState(info); ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setProducerState(state); producerExchange.setMutable(true); producerExchange.setConnectionContext(context); context.getBroker().send(producerExchange, message); } finally { context.setProducerFlowControl(originalFlowControl); }
相关推荐
ActiveMQ队列消息过期时间设置和自动清除解决方案.docx
详细描述了ActiveMQ消息过期-时间设置和自动清除解决方案。
这个一个activemq服务项目,内有activemq事务,集群,我在里面作了一个spring的事务,Atomikos的事务相应jar包。希望大家下载给出建议,(我在做这个时花了很长的时间,下载其他的文件也花了很多时间,所以在下载时,...
基于Springboot+ActiveMQ事务==本地事件表+activemq,即利用activemq+本地事件表实现分布式事务的功能
activemq 通过ajax发送接收消息简单例子
用C#实现的ActiveMQ发布/订阅消息传送源程序
activemq向android推送消息实例,测试环境activemq5.9.1版,别忘了修改你的主机地址
百度spring整合activemq 发现几乎都只是在xml文件配置固定的消息队列而且太麻烦。并没有根据需求进行动态生成主题和队列。本文档参考了纯粹的activemq java代码和百度上的demo,很简洁的实现了动态消息队列的生成和...
ActiveMQ RabbitMQ RokcetMQ Kafka实战 消息队列中间件视频教程
java JMS模拟ActiveMQ代理服务器并实现消息收发,这里是工程源码,已经过测试,可以直接使用。
本代码关于activemq-cpp的核心代码参考的chenxun2009的博客园,其他部分包括:从配置文件中读取消息通道,过滤条件等信息。
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
ActiveMQ RabbitMQ RokcetMQ Kafka实战 消息队列中间件视频教程
activeMQ的发送消息后接收者返回信息
分布式事务就是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器分别位于不同的分布式系统的不同节点之上。简单的说,就是一次大的操作由不同的小操作组成,这些小的操作分布在不同的服务器上,且属于...
springboot集成activemq实现消息接收demo
activemq queue模式,事务、应答、转发模式、MessageConsumer的receive阻塞方法的测试
使用ActiveMQ实现了JMS的点对点的消息模型,将发送者和接受者分别放在了两个不同的项目中。
springboot2整合activemq的demo内含queue消息和topic消息,需要使用者修改application.yml的连接地址信息就可以了,端口号是默认的可以不用修改