How to save messages and Topics in Activemq?

泄露秘密 提交于 2019-12-12 00:33:32

问题


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



来源:https://stackoverflow.com/questions/18736355/how-to-save-messages-and-topics-in-activemq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!