生活随笔
收集整理的這篇文章主要介紹了
ActiveMQ的消息重发策略和DLQ处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
ActiveMQ的消息重發策略和DLQ處理 博客分類: MQ
在以下三種情況中,ActiveMQ消息會被重發給客戶端/消費者:?
1.使用一個事務session,并且調用了rollback()方法;?
2.一個事務session,關閉之前調用了commit;?
3.在session中使用CLIENT_ACKNOWLEDGE簽收模式,并且調用了Session.recover()方法。?
Broker根據自己的規則,通過BrokerInfo命令包和客戶端建立連接,向客戶端傳送缺省發送策略。但是客戶端可以使用ActiveMQConnection.getRedeliveryPolicy()方法覆蓋override這個策略設置。?
Java代碼
RedeliveryPolicy?policy?=?connection.getRedeliveryPolicy();??policy.setInitialRedeliveryDelay(500);??policy.setBackOffMultiplier(2);??policy.setUseExponentialBackOff(true);??policy.setMaximumRedeliveries(2);??
一旦消息重發嘗試超過重發策略中配置的maximumRedeliveries(缺省為6次)時,會給broker發送一個"Poison ack",通知它,這個消息被認為是一個毒丸(a poison pill),接著broker會將這個消息發送到DLQ(Dead Letter Queue),以便后續分析處理。?
缺省死信隊列(Dead Letter Queue)叫做ActiveMQ.DLQ;所有的未送達消息都會被發送到這個隊列,以致會非常難于管理。你可以設置activemq.xml文件中的destination policy map的"individualDeadLetterStrategy"屬性來修改.?
Java代碼
<broker...>????<destinationPolicy>??????<policyMap>????????<policyEntries>??????????<!--?Set?the?following?policy?on?all?queues?using?the?'>'?wildcard?-->??????????<policyEntry?queue=">">????????????<deadLetterStrategy>??????????????<!--????????????????Use?the?prefix?'DLQ.'?for?the?destination?name,?and?make????????????????the?DLQ?a?queue?rather?than?a?topic??????????????-->??????????????<individualDeadLetterStrategy????????????????queuePrefix="DLQ."?useQueueForQueueMessages="true"?/>????????????</deadLetterStrategy>??????????</policyEntry>????????</policyEntries>??????</policyMap>????</destinationPolicy>????...??</broker>??
自動丟棄過期消息(Expired Messages)?
一些應用可能只是簡單的丟棄過期消息,而不想將它們放到DLQ中,完全跳過了DLQ。在dead letter strategy死信策略上配置processExpired屬性為false,可以實現這個功能。?
Java代碼
<broker...>????<destinationPolicy>?????<policyMap>???????<policyEntries>?????????<!--?Set?the?following?policy?on?all?queues?using?the?'>'?wildcard?-->?????????<policyEntry?queue=">">???????????<!--?????????????Tell?the?dead?letter?strategy?not?to?process?expired?messages?????????????so?that?they?will?just?be?discarded?instead?of?being?sent?to?????????????the?DLQ???????????-->???????????<deadLetterStrategy>?????????????<sharedDeadLetterStrategy?processExpired="false"?/>???????????</deadLetterStrategy>?????????</policyEntry>???????</policyEntries>?????</policyMap>????</destinationPolicy>??...??</broker>??
將非持久消息(non-persistent messages)放入死信隊列?
ActiveMQ缺省不會將未發到的非持久消息放入死信隊列。如果一個應用程序并不想將消息message設置為持久的,那么記錄下來那些未發送到的消息對它來說往往也是沒有價值的。不過如果想實現這個功能,可以在dead-letter strategy死信策略上設置processNonPersistent="true"?
Java代碼
<broker...>????<destinationPolicy>?????<policyMap>???????<policyEntries>?????????<!--?Set?the?following?policy?on?all?queues?using?the?'>'?wildcard?-->?????????<policyEntry?queue=">">???????????<!--?????????????Tell?the?dead?letter?strategy?to?also?place?non-persisted?messages?????????????onto?the?dead-letter?queue?if?they?can't?be?delivered.???????????-->???????????<deadLetterStrategy>?????????????<sharedDeadLetterStrategy?processNonPersistent="true"?/>???????????</deadLetterStrategy>?????????</policyEntry>???????</policyEntries>?????</policyMap>????</destinationPolicy>??...??</broker>?? http://sharong.iteye.com/blog/1987171
轉載于:https://my.oschina.net/xiaominmin/blog/1597342
總結
以上是生活随笔為你收集整理的ActiveMQ的消息重发策略和DLQ处理的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。