问题
While reading messages from a dynamic queue(ActiveMQ)(Pending Messages=1000), i had acknowledge each message,now the number of Messages Dequeued=1000.
Is there any way to place all dequeued messages again into Queue. Any solution to get all messages backup physically.
Thanks in advance
回答1:
Once broker get acknowledgment from consumer, it removes message from persistence store [KahaDB/database as per configuration] of broker.
Hence if you have sent all messages to another queue or broker from your queue, you can resend those messages to your original queue. However all depends what you did with messages. If you have consumed it using MDB/java code etc, you will not be able to place them again to original queue.
回答2:
Dequeued messages are not designed can be seen in activemq, you need your own logic to save them elsewhere.
ActivemMQ also give some functions to make that easier, like Mirrored Queues(http://activemq.apache.org/mirrored-queues.html), or the log plugin.
But still you need to save messages elsewhere and backup them by yourself.
回答3:
to backup enqueued messages when you need the body of messages :
you can add this to your activemq.xml
this will save a copy of messages to a file under ${activemq.base}/bin/data/activemq/
a file by day and queue
<bean id="ActiveMQVMConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?create=false&waitForStart=10000"/>
<property name="userName" value="${activemq.username}"/>
<property name="password" value="${activemq.password}"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory" ref="ActiveMQVMConnectionFactory"/>
</bean>
<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:*?mapJmsMessage=false&selector=CamelFileNameProduced IS NULL" />
<choice>
<when>
<simple>${in.headers.CamelFileNameProduced} == null</simple>
<setHeader headerName="CamelJmsDestinationName">
<simple>${in.header.JMSDestination.physicalName}</simple>
</setHeader>
<transform>
<simple>${in.body}\n</simple>
</transform>
<to uri="file://data/activemq/?fileExist=Append&fileName=routeMessages-${in.header.JMSDestination.physicalName}-${date:now:yyyyMMdd}.txt" />
<to uri="activemq:dummy" />
</when>
</choice>
</route>
</camelContext>
If you only need metadata :
Destination advisoryDestination = session.createTopic("ActiveMQ.Advisory.MessageConsumed.>");
MessageConsumer consumer = session.createConsumer(advisoryDestination);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
System.out.println(msg);
System.out.println(((ActiveMQMessage) msg).getMessageId());
}
});
http://activemq.apache.org/advisory-message.html
来源:https://stackoverflow.com/questions/43625848/how-to-see-dequeued-messages-in-activemq