ActiveMQ拦截器使用和原理
来源:互联网 发布:网络教育文凭出国留学 编辑:程序博客网 时间:2024/06/05 14:58
在ActiveMQ中使用拦截器和过滤器的使用多采用插件的形式实现,继承BrokerFilter实现BrokerPlugin接口类。BrokerFilter实质一个实现Broker接口的类。
public interface BrokerPlugin {
/**
* Installs the plugin into the interceptor chain of the broker, returning the new
* intercepted broker to use.
*/
Broker installPlugin(Broker broker) throws Exception;
}
1. 日志拦截器
日志拦截器是Broker的一个拦截器,默认的日志级别为INFO。你如你想改变日志的级别。这个日志拦截器支持Commons-log和Log4j两种日志。
Attribute
Description
Default Value
logAll
Log all Events
false
logMessageEvents
Events related with producing, consuming and dispatching messages
false
logConnectionEvents
Events related to connections and sessions
true
logTransactionEvents
Events related to transaction handling
false
logConsumerEvents
Events related to consuming messages
false
logProducerEvents
Events related to producing messages
false
logInternalEvents
Events normally not of Interest for users like failover, querying internal objects etc
false
默认连接时间日志是开启,其他均未开启。通过activemq开启相关的日志。
<plugins>
<!-- lets enable detailed logging in the broker but ignore ConnectionEvents -->
<loggingBrokerPlugin logAll="true" logConnectionEvents="false"/>
</plugins>
2. 统计拦截器
从ActiveMQ5.3开始,StatisticsPlugin插件被用作检测Broker中统计的插件。注意消息必须包含replyTo的消息头,如果是在JMS那么需要采用jmsReplyTo消息头,否则消息将被统计忽略。ReplyTo消息头包含了你想检查统计的消息。统计消息是一个MapMessage.
检查Broker的信息,仅仅需要一个名称为ActiveMQ.Statistics.Broker并且有一个replyTo的消息头的Destination。为了检测所有destination,你需要一个名称为ActiveMQ.Statistics.Destination.<destination-name>或者ActiveMQ.Statistics.Destination.<wildcard-expression>并且有一个replyTo的消息头。如果许多Destination匹配相关的模糊匹配表达式,那么统计的消息将被发送到replyTo的Destination.
<plugins>
<!-- lets enable detailed logging in the broker but ignore ConnectionEvents -->
<statisticsBrokerPlugin/>
</plugins>
Statistics插件发送消息到特殊的目标。
下面是一个统计Broker的消息
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
String queueName = "ActiveMQ.Statistics.Broker";
Queue testQueue = session.createQueue(queueName);
MessageProducer producer = session.createProducer(testQueue);
Message msg = session.createMessage();
msg.setJMSReplyTo(replyTo);
producer.send(msg);
MapMessage reply = (MapMessage) consumer.receive();
assertNotNull(reply);
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.out.println(name + "=" + reply.getObject(name));
}
查询Destination的统计信息
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue testQueue = session.createQueue("TEST.FOO");
MessageProducer producer = session.createProducer(null);
String queueName = "ActiveMQ.Statistics.Destination." + testQueue.getQueueName()
Queue query = session.createQueue(queueName);
Message msg = session.createMessage();
producer.send(testQueue, msg)
msg.setJMSReplyTo(replyTo);
producer.send(query, msg);
MapMessage reply = (MapMessage) consumer.receive();
assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements());
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name + "=" + reply.getObject(name));
}
- ActiveMQ拦截器使用和原理
- ActiveMQ中advisory的使用和原理
- MyBatis拦截器的使用和设计原理
- 监听器和拦截器原理
- jeesite mybatis拦截器sql语句与activemq的使用
- struts2拦截器的原理和写法
- struts2 拦截器的原理和实现
- Struts2拦截器定义和原理
- Struts2 拦截器原理和配置
- activeMQ的原理及使用
- 过滤器和拦截器使用
- ActiveMQ安装和使用
- activemq安装和使用
- springMVC --拦截器详细,使用和自定义拦截器
- 拦截器和过滤器比较和使用
- struts 拦截器和过滤器的区别和原理
- 拦截器:Interceptor(原理)
- Struts2拦截器原理
- poll, select &&nbs…
- Linux IIC驱动笔记
- new style I2C设备驱动…
- oracle
- poll机制分析
- ActiveMQ拦截器使用和原理
- uevent分析
- usb高速握手过程
- Linux中软中断机制分析
- Linux中断(interrupt)子系统之三…
- 进程上下文和中断上下文
- 对Linux内核中进程上下文和中断上…
- Linux输入子系统-数据结构关系
- 对输入子系统分析总结