简体   繁体   中英

Iterate over non-persistent activemq expired messages in ActiveMQ.Advisory.Expired.Queue

Iam building an application on activemq where iam sending a message from producer where my delivery mode is NON_PERSISTENT ( iam not dealing with PERSISTENT delivery mode and i know it will be stored in DLQ-which is not my design )and have set a time to live for the message using producer.setTimeToLive(2000).As the functionality says the message will expire in 2 seconds.

I see that the expired messages are enqueued in the ActiveMQ.Advisory.Expired.Queue in the topic section of activeMQ admin console ie http://localhost:8161/admin/topics.jsp .

My question is how do i iterate over the ActiveMQ.Advisory.Expired.Queue so that i can access the MessageID of the expired message.Any code example would be great.

A subscription to the destination ActiveMQ.Advisory.Expired.Queue is like any topic and it returns an ActiveMQMessage. There is DataStructure objects (ConsumerInfo, ProducerInfo,ConnectionInfo...) can be retrieve via getDataStructure method of ActiveMQMessage.

doc http://activemq.apache.org/advisory-message.html

example:

Destination advisoryDestination = AdvisorySupport.getExpiredQueueMessageAdvisoryTopic(destination)
MessageConsumer consumer = session.createConsumer(advisoryDestination);
consumer.setMessageListener(this);

public void onMessage(Message msg){
    String messageId =   msg.getJMSMessageID();
    String orignalMessageId =   msg.getStringProperty(org.apache.activemq.advisory.AdvisorySupport.MSG_PROPERTY_MESSAGE_ID);
    if (msg instanceof ActiveMQMessage){
        try {
             ActiveMQMessage aMsg =  (ActiveMQMessage)msg;
             ProducerInfo prod = (ProducerInfo) aMsg.getDataStructure();
        } catch (JMSException e) {
            log.error("Failed to process message: " + msg);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM