Search code examples
javaactivemq-classicjms-topic

ActiveMQ durable topics, messages pre-subscription?


In our business requirement, we need to transmit updates to a couple of thousands of clients, distributed across the country. Thing is, many of these clients connect to us using 3g network, so, many connect/disconnect occurs... The updates we need to deliver are things like "Enterprise A can not be cashed anymore", or "Enterprise B is able to be cashed again", We were thinking in using ActiveMQ durable topics to deliver these updates. It is my understanding that once a client connects to a durable topic, even if he looses connection, whenever he gets back, he receives the messages sent to that topic while he was offline. Big question is, what if a client starts our system, but messages were sent to the durable topic he is suscribing to, previous to his subscription. This case is:

Durable Topic is created
Message 1 is sent to the Durable Topic
Message 2 is sent to the Durable Topic
Client A subscribes to Durable Topic
Message 3 is sent to the Durable Topic
Message 4 is sent to the Durable Topic
Client A goes offline
Message 5 is sent to the Durable Topic
Message 6 is sent to the Durable Topic
Client A goes online

As per ActiveMQ papers, Client A will receive messages 3 to 6 with no problem. But what about Messages 1 and 2? We can not afford to loose those messages...

Thanks in advance!


Solution

  • For how long should "message 1-2" be available. Think of adding a client subscriber after many years of messages has passed. Should all those be delivered as well?

    If you intend to submit the entire history of messages to new clients, I suggest some "initial load" procedure where the client ask for the history. Maybe using JMS request reply or some other feature.

    Anyway, if you want your client to be able to get some messages from before it was created, you can use a retroactive consumer.

    Then you need to specify a recovery policy on the broker side.

    You can recover based on time, count, memory size or similar. See options and settings here.

    Use a destination name such as: UPDATE.TOPIC?consumer.retroactive=true to enable this feature on the client side.