如何在Activemq中保存消息和主题? [英] How to save messages and Topics in Activemq?
问题描述
我有一个Queue
和Topic
,其中Activemq
中有2条消息.如果我重新启动Activemq
,我丢失了消息,也丢失了Topic
.
I have a Queue
and Topic
with 2 messages in Activemq
.If I restart Activemq
.I am losing messages and also Topic
.
即使重新启动Activemq
,我也不想丢失任何来自Topic
和Queue
的消息.是否有可能.
Even If I restart Activemq
,I don't want to lose any messages from any Topic
and Queue
.Is it possible.
我正在使用Activemq 5.8.0
.
推荐答案
生产者产生消息并将其发送到主题,无论哪个 消费者在该时间点运行,将收到消息. 如果您希望现在尚未启动但正在运行的使用者 将来要收到此消息,您将必须告诉经纪人 保留消息并存储有关该消息的信息 消费者尚未收到该消息.
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.
在消费者中,
1.设置clinetId.因为Topic应该知道哪个消费者还没有收到消息.或已收到消息.
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.应该为您的主题创建一个持久订阅者
2. Should be creating a durable subscriber for your topic
Connection.createDurableSubscriber()
3.将您的侦听器添加到该订户.
3. Add your listener to this subscriber.
subscriber.setMessageListener(yourlistener)
4.收到消息后,您将不得不确认
4. Once you receive the message, you will have to acknowledge it
此链接显示了它是如何完成的:但是我想它是在c#中.
This link shows how it is done: But its in c# i guess.
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
这篇关于如何在Activemq中保存消息和主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!