DURABLE在queue和topic中的區別

DURABLE在queue和topic中的區別


durable是爲了防止宕機等異常而導致消息無法及時接收設計的。

這個對queue無太多影響,但對topic影響比較大。

本文引用

http://activemq.apache.org/how-do-durable-queues-and-topics-work.html

 

對queue的影響

Durable queueskeep messages around persistently for any suitable consumer to consumethem. Durable queues do not need to concern themselves with whichconsumer is going to consume the messages at some point in the future.There is just one copy of a message that any consumer in the future canconsume.

 

對topic的影響

Durable topics however are different as they must logically persistan instance of each suitable message for every durable consumer - sinceeach durable consumer gets their own copy of the message.

 

對topic影響舉例說明

For example imagine a durable subscriber S starts up subscribing totopic T at time D1. Some publisher sends messages M1, M2, M3 to thetopic and S will receive each of these messages. Then S is stopped andthe publisher continues to send M4, M5.

When S restarts at D2, the publisher sends M6 and M7. Now S willreceive M4, M5 followed by M6 and M7 and all future messages. i.e. Swill receive all messages from M1..M7.

This is the difference between durable and non-durable consuming. IfS were a non-durable consumer then it would only have received M1, M2,M3 and M6, M7 - not M4 and M5. i.e. because the subscription isdurable, S will receive every message sent to T whether the subscriberis running or not. For non-durable topics, only messages delivered tothe topic T when S is running are delivered.

So for durable topic subscription, the JMS provider needs to be ableto identify S when it shuts down and later on in the future reconnects,so it can know what messages to send to it while it was not running.JMS specification dictates that the identification of S is done by acombination of the clientID and the durable subscriber name. This is sothat the JMS connection S uses can have many different durablesubscriptions on different topics or on the same topic with differentselectors - yet the JMS provider can know which message for whichsubscription to keep around for it.

So setting the clientID on a JMS connection is vital (along withusing a sensible durable consumer name) for durable topic subscription.Its not an issue for other QoS

 

在topic模式下,如果設置durable爲true,就要設置clientID給 JMS provider,讓他來維護記錄 每個訂閱者接收消息狀態。同時topic的訂閱者沒接收一條消息也要反饋一條成功接收信息給JMS provider。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章