How to save messages and Topics in Activemq?

2019-08-30 06:08发布

问题:

I have a Queue and Topic with 2 messages in Activemq.If I restart Activemq.I am losing messages and also Topic.

Even If I restart Activemq,I don't want to lose any messages from any Topicand Queue.Is it possible.

I am using Activemq 5.8.0.

回答1:

A producer produces the message and send it to the Topic, which ever consumer is running at that point of time, will receive the message. If you want consumer which is not up now, but might be running in future to get this message, you will have to tell the Broker to persist the message and store the information that this perticular consumer has not received the message.

If you have working code with-out durable subscriber, you will have to do the following changes.

In the consumer,
1. set the clinetId. Because Topic should know which consumer is yet to receive the message. Or has received the message.

Connection.setClientID(String)

2. Should be creating a durable subscriber for your topic

Connection.createDurableSubscriber()

3. Add your listener to this subscriber.

subscriber.setMessageListener(yourlistener)

4. Once you receive the message, you will have to acknowledge it

This link shows how it is done: But its in c# i guess.

http://myadventuresincoding.wordpress.com/2011/08/16/jms-how-to-setup-a-durablesubscriber-with-a-messagelistener-using-activemq/

Read these links for more info :

http://activemq.apache.org/how-do-durable-queues-and-topics-work.html http://activemq.apache.org/why-do-i-not-receive-messages-on-my-durable-topic-subscription.html http://activemq.apache.org/manage-durable-subscribers.html