简体   繁体   English

迭代 ActiveMQ.Advisory.Expired.Queue 中的非持久性 activemq 过期消息

[英]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.我正在 activemq 上构建一个应用程序,其中我从生产者发送一条消息,其中我的交付模式为 NON_PERSISTENT(我不处理 PERSISTENT 交付模式,我知道它将存储在 DLQ 中 - 这不是我的设计)并设置了生存时间对于使用 producer.setTimeToLive(2000) 的消息。正如功能所说,消息将在 2 秒后过期。

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 .我看到过期的消息在 activeMQ 管理控制台的主题部分的ActiveMQ.Advisory.Expired.Queue中排队,即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.我的问题是如何遍历ActiveMQ.Advisory.Expired.Queue以便我可以访问过期消息的MessageID 。任何代码示例都会很棒。

A subscription to the destination ActiveMQ.Advisory.Expired.Queue is like any topic and it returns an ActiveMQMessage.对目标ActiveMQ.Advisory.Expired.Queue 的订阅就像任何主题一样,它返回一个 ActiveMQMessage。 There is DataStructure objects (ConsumerInfo, ProducerInfo,ConnectionInfo...) can be retrieve via getDataStructure method of ActiveMQMessage.可以通过 ActiveMQMessage 的 getDataStructure 方法检索 DataStructure 对象(ConsumerInfo、ProducerInfo、ConnectionInfo...)。

doc http://activemq.apache.org/advisory-message.html文档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);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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