Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual topics/queues and durability

Tags:

activemq

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 ?

like image 960
Jan-Olav Eide Avatar asked Jan 26 '12 14:01

Jan-Olav Eide


People also ask

What is the difference between queue topic and virtual?

While queues tighten producer and consumer, topics lack of an easy way to recover errors of a single consumer. Virtual topics are provide a solution for both problems. Producer and consumers are decoupled by a publish-and-subscribe pattern while error recovery can be done on individual queues.

What is queue and Topic?

A queue means a message goes to one and only one possible subscriber. A topic goes to each and every subscriber.

Does ActiveMQ have topics?

Both ActiveMQ queue and ActiveMQ topic are places where messages are sent. The difference between ActiveMQ Queue and Topic comes down to who receives the message.

What is Artemis MQ?

Apache ActiveMQ Artemis is an asynchronous messaging system, an example of Message Oriented Middleware , we'll just call them messaging systems in the remainder of this book.


2 Answers

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
like image 160
srodriguez Avatar answered Oct 11 '22 14:10

srodriguez


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.

like image 25
Gary Liu Avatar answered Oct 11 '22 13:10

Gary Liu