Search code examples
javaactivemq-classicdurabilitydurable-subscriptionvirtual-topic

Using durable subscribers with virtual topics in ActiveMQ and does Subscription Recovery Policy play any role?


I am a bit confused here on how to properly use ActiveMQ.

What i'm trying to do

I have system A which produces messages to a virtual topic. Then there's system B and C which both consume messages from the same virtual topic. There is a chance that system B or C might go offline. So when they come back online, I need them to receive all messages that were produced during the offline period.

What I have tried so far

I have read about durable subscribers (http://activemq.apache.org/how-do-durable-queues-and-topics-work.html and Virtual topics/queues and durability). This seems to fit my problem description and after doing some implementation, everything seems to work as I initially wanted.

What creates confusion

Then I read about Subscription Recovery Policy (http://activemq.apache.org/subscription-recovery-policy.html). Is this something I should configure or am I completely misunderstanding something? For example, if I want to store a specified amount of messages, should I configure a FixedCountSubscriptionRecoveryPolicy or should I look into some pendingMessageLimitStrategy?


Solution

  • First question is why use durable topic subscriptions on the Topic portion of the Virtual Topic when the main point of a Virtual Topic is to publish to the Topic (e.g. VirtualTopic.FOO) and then create Queue consumers on the matching filter value (e.g. Consumer.A.VirtualTopic.FOO) ?

    In regards to the recovery policy, they are only applicable to Topic subscriptions which are not the same thing as Durable Topic subscriptions. For a plain old Topic subscription the messages sent to the Topic are only held in the broker for that subscription as long as it is connected, once it drops all messages that were in play for that subscription are dropped. What the subscription recovery policy does is to create a configurable cache of sorts that allows a Topic subscription to be created and get a replay of messages sent to the matching Topic. This is unnecessary for a Durable Topic subscription as message sent to the Topic it is subscribed to are stored in the broker message store whenever the subscriber is offline.

    The recovery policies can mix into durable Topic subscriptions only in a few edge cases such as messages sent to a Topic marked non-persistent or on first subscribe where some past message could be recovered from memory and played into the new Durable subscription as a sort of primer but that's about all they are good for in the durable case.

    In any event you are better off using virtual Topics the way they were intended by creating Queue consumers as this mechanism offers many advantages over durable Topic subscriptions. The ActiveMQ documentation on Virtual Destinations explains all this.