DURABLE在queue和topic中的区别

来源:互联网 发布:js继承是什么 编辑:程序博客网 时间:2024/05/16 23:47

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 otherQoS

 

在topic模式下,如果设置durable为true,就要设置clientID给 JMS provider,让他来维护记录 每个订阅者接收消息状态。同时topic的订阅者没接收一条消息也要反馈一条成功接收信息给JMS provider。

0 0