4

In my program, I have two modules :- Publisher and Subscriber which communicate via Topic.

I understand that in order to receive messages by subscriber, it should be started before publisher. But there may be a scenario where the subscriber goes down for some reason and needs to be restarted. Is there any way, by which if I start the Subscriber after Publisher, then also it should be able to receive message?

Vishal
  • 189
  • 3
  • 11

3 Answers3

2

Adding a code example by using spring DMLC and durable subscribers. It's harder to achieve this with a plain JMSTemplate (you tagged this, so I guess you are using JMS Templates to receive?), since you have to grab the session from the template and create the durable consumer yourself. This is automatically handled 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>
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • Thanks. I think that it's `durableSubscriptionName` now rather than `durableSuscriberName` – Kirby May 07 '15 at 19:56
1

If you are only interested in the disconnect-reconnect scenario, I think a durable subscriber is what you are looking for.

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

musicin3d
  • 1,028
  • 1
  • 12
  • 22
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
1

In general if you want to account for a subscriber going offline and returning without missing any messages you would use JMS Durable Subscriptions. This allows your subscriber to receive any messages it missed while offline. Note that the caveat here is that is needs to have subscribed once first before it will start to collect offline messages.

Besides the standard JMS Durable consumer model ActiveMQ also provides the retroactive consumer. Another possibility is Virtual destinations.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42