使用JMX控制台-jConsole进行ActiveMQ监视

时间:2016-10-10 07:41:42

标签: jms activemq spring-jms

如何使用JMX控制台-jConsole查看ActiveMQ JMS中的使用者使用的消息?

1 个答案:

答案 0 :(得分:1)

enter image description here 要执行此操作,您可以使用jconsole或visualVM浏览主题ActiveMQ.Advisory.MessageConsumed.Topic.YourTopicName或队列ActiveMQ.Advisory.MessageConsumed.Queue.YourQueueName,这可以通过咨询消息http://activemq.apache.org/advisory-message.html进行,您需要通过添加此功能在代理配置中启用此功能:

    <destinationPolicy>
        <policyMap>
          <policyEntries>
            <!--  http://activemq.apache.org/advisory-message.html -->
            <policyEntry topic=">" advisoryForConsumed="true" />
            <policyEntry queue=">" advisoryForConsumed="true" />
          </policyEntries>
        </policyMap>
    </destinationPolicy>

用于浏览咨询消息的代码。

        Destination advisoryDestination = AdvisorySupport.getMessageDeliveredAdvisoryTopic(destination);
        Destination advisoryDestination = AdvisorySupport.getMessageDiscardedAdvisoryTopic(destination);
        Destination advisoryDestination = AdvisorySupport.getMessageConsumedAdvisoryTopic(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;
                     ConsumerInfo consumerInfo = (ConsumerInfo) aMsg.getDataStructure();
                } catch (JMSException e) {
                    log.error("Failed to process message: " + msg);
                }
            }
        }