繁体   English   中英

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

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

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

我看到过期的消息在 activeMQ 管理控制台的主题部分的ActiveMQ.Advisory.Expired.Queue中排队,即http://localhost:8161/admin/topics.jsp

我的问题是如何遍历ActiveMQ.Advisory.Expired.Queue以便我可以访问过期消息的MessageID 。任何代码示例都会很棒。

对目标ActiveMQ.Advisory.Expired.Queue 的订阅就像任何主题一样,它返回一个 ActiveMQMessage。 可以通过 ActiveMQMessage 的 getDataStructure 方法检索 DataStructure 对象(ConsumerInfo、ProducerInfo、ConnectionInfo...)。

文档http://activemq.apache.org/advisory-message.html

例子:

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