Virtual topics/queues and durability

做~自己de王妃 提交于 2019-12-10 14:58:23

问题


What will happen to messages posted to a virtual topic when there are no consumers listening ? Will the broker hold them for a certain while until a subscriber is available ?

More specifically : At T0 and T1 messages M0 and M1 are posted. At T2, consumer C1 connects, will he receive M0 and M1 ? Obviously messages M2 and M3 posted at T3 and T4 will be received by C1, but what will a new Consumer, C2, that connects at T5 receice ? All messages, M2 and M3, or none ?


回答1:


It depends on the nature of the topic: if the topic is durable (has durable consumers subscribing to it), the broker will hold the messages in the topic until all the durable consumers consumes the messages. if the topic is non-durable (no durable consumers), the message will not even be sent to the topic, as there will be no durable subscription.

For your example, I'll consider that you are using durable subscriptions / consumers: Case 1:

  • T-2 C1 and C2 make durable subscription to the topic
  • T-1 C1 and C2 disconnect
  • T0: M0 is posted
  • T1: M1 is posted
  • T2: C1 connects. C1 receives M0 and M1
  • T3: M3 is posted. C1 receives M3
  • T4: M4 is posted. C1 receives M4
  • T5: C2 connects, C2 receives M0, M1, M2, M3, M4

That's because they are holding durable subscriptions You need to be very careful when using durable topics / queues: if the consumer doesn't unsubscribe, the broker will hold the messages until the message store explodes. You will need to make sure it doesn't happen (by setting eviction policies and / or putting a Time to Live on the messages). Of course the previous example will vary depending when the consumer does the durable subscription.

If you are using non-durable topics:

  • T-2 C1 and C2 make normal subscription to the topic
  • T-1 C1 and C2 disconnect
  • T0: M0 is posted
  • T1: M1 is posted
  • T2: C1 connects. C1 does not receive anything
  • T3: M3 is posted. C1 receives M3
  • T4: M4 is posted. C1 receives M4
  • T5: C2 connects, C2 does not receive anything



回答2:


There are two ways to allow messages published to a virtual topic to suivive. The first one is through the durable subscriber and the other is that the publisher sends messages with delivery mode "PERSISTENT". When messages are published with the delivery mode of "PERSISTENT", the message will be saved on disk, otherwise, it will be save in-memory.




回答3:


Why can't there be a observer/observable pattern - taking the example above:

When M0 is posted, C1 and C2 (consumers subscribed) are woken and can consume the event? I see this pattern better than the durable and non-durable - a hybrid approach.



来源:https://stackoverflow.com/questions/9019248/virtual-topics-queues-and-durability

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!