DLQ-死信队列(Dead Letter Queue)用来保存处理失败或者过期的消息。出现以下情况时,消息会被再投递
消费端:
1)A transacted session is used and rollback() is called.
2)A transacted session is closed before commit is called.
3)A session is using CLIENT_ACKNOWLEDGE and Session.recover() is called.
服务端:
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
producer.setTimeToLive(time); 超过指定时间没有发送消息出去将会进入死讯队列
http://javavsnet.iteye.com/blog/1972523