2016年7月6日星期三

ActiveMQ_031:使用 Logging Interceptor 获取感兴趣的信息

环境:MAC OS X 10.11.5 + ActiveMQ 5.13.3

如果你想记录消息的各种事件,比如:每一条消息的发送与接收(包括消息内容),连接的创建的,Session 的创建,事务的处理等等,可以使用 Logging Interceptor 特性。

配置如下,在 broker 的定义的最开始的地方,增加如下内容:
<plugins>

    <!-- lets enable detailed logging in the broker but ignore ConnectionEvents -->
    <loggingBrokerPlugin logAll="true" logConnectionEvents="false"/>

    <timeStampingBrokerPlugin zeroExpirationOverride="1000" ttlCeiling="60000" futureOnly="true"/>
    <traceBrokerPathPlugin/>

</plugins>

可以使用的参数有:
(1)logAll 记录所有事件,默认 false。
(2)logConnectionEvents 记录有关连接事件,默认 true。
(3)logTransactionEvents 记录事务处理,默认 false。
(4)logConsumerEvents 记录消息消费事件,默认 false。
(5)logProducerEvents 记录消息生产事件,默认 false。
(6)logSessionEvents 记录有关 Session 事件,默认 true。

如上设置后,会输出如下信息:
2016-07-06 16:48:13,250 | INFO  | Sending message: ActiveMQTextMessage {commandId = 19, responseRequired = true, messageId = ID:MaPingdeMacBook-Pro.local-56634-1467794885454-1:1:1:1:15, originalDestination = null, originalTransactionId = null, producerId = ID:MaPingdeMacBook-Pro.local-56634-1467794885454-1:1:1:1, destination = queue://FirstQueue, transactionId = null, expiration = 1467794894250, timestamp = 1467794893250, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@7aba5298, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false, text = #### ActiveMq发送的消息15} | org.apache.activemq.broker.util.LoggingBrokerPlugin | ActiveMQ Transport: tcp:///127.0.0.1:56635@61619

参考文献:
1. http://activemq.apache.org/logging-interceptor.html