ACTIVEMQ - How can a subscriber receive topic messages when launched after the publisher?

In my program, I have two modules: - Publisher and Subscriber, which exchange data through a theme.

I understand that in order to receive messages from the subscriber, he must be launched in front of the publisher. But a scenario may arise in which the subscriber refuses for some reason and needs to be restarted. Is there a way by which, if I started the subscriber after the publisher, then he should also be able to receive a message?

+4
source share
3 answers

If you are only interested in the disconnect scenario, I think that a reliable subscriber is what you are looking for.

http://activemq.apache.org/how-do-durable-queues-and-topics-work.html

+1
source

Adding sample code using spring DMLC and trusted subscribers. It is harder to do this with a simple JMSTemplate (did you note this, so I guess you use JMS templates to get it?), Since you need to grab a session from the template and create a strong consumer yourself. This is automatically processed for you if you use the DMLC approach.

<bean id="myDurableConsumer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="myCf" /> <property name="sessionTransacted" value="true" /> <property name="subscriptionDurable" value="true"/> <property name="durableSubscriberName" value="myDurableNameThatIsUniqueForThisInstance" /> <property name="destinationName" value="someTopic" /> <property name="messageListener" ref="myListener" /> < /bean> 
+2
source

In general, if you want to consider that the subscriber goes offline and returns without any messages, you should use JMS Durable Subscriptions. This allows your subscriber to receive any messages that he missed while offline. Please note that you must specify here that you must first subscribe before he begins to collect offline messages.

In addition to the standard consumer model JMS Durable ActiveMQ, a return consumer is also provided. Another option is Virtual Destinations .

+1
source

Source: https://habr.com/ru/post/1441208/


All Articles