如何解决如何启用activemq插件
我正在尝试为activemq(5.15.13)创建一个拦截器。 我使用https://activemq.apache.org/interceptors中的代码并将其编译为jar文件。 我将jar文件添加到/ lib文件夹。
然后我将其添加到activemq.xml
<plugins>
<loggingBrokerPlugin logAll="true" logConnectionEvents="true"/>
<bean xmlns="http://www.springframework.org/schema/beans" id="myPlugin" class="com.xxx.mqplugin.MyPlugin"/>
</plugins>
我知道
jvm 1 |信息|创建的LoggingBrokerPlugin:LoggingBrokerPlugin(logAll = true,logConnectionEvents = true,logSessionEvents = true,logConsumerEvents = false,logProducerEvents = false,logTransactionEvents = false,logInternalEvents = false)
但是我的插件没什么.. 如何注册并启用我的插件?
package com.xxx.mqplugin;
import java.util.logging.Logger;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerFilter;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.region.MessageReference;
import org.apache.activemq.command.ConnectionInfo;
import org.apache.activemq.command.ProducerInfo;
import org.apache.activemq.command.SessionInfo;
public class MyBroker extends BrokerFilter {
public MyBroker(Broker next) {
super(next);
}
public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception {
// Your code goes here
System.out.println("addConnection:" + info.toString());
Logger.getLogger("test").info("addConnection:" + info.toString());
// Then call your parent
super.addConnection(context,info);
}
public void addSession(ConnectionContext context,SessionInfo info) throws Exception {
// Your code goes here...
System.out.println("addSession:" + info.toString());
Logger.getLogger("test").info("addSession:" + info.toString());
// Then call your parent
super.addSession(context,info);
}
@Override
public void addProducer(ConnectionContext context,ProducerInfo info) throws Exception {
// Your code goes here...
System.out.println("addProducer:" + info.toString());
Logger.getLogger("test").info("addProducer:" + info.toString());
super.addProducer(context,info);
}
@Override
public void messageDelivered(ConnectionContext context,MessageReference messageReference) {
System.out.println("messageDelivered:" + messageReference.toString());
Logger.getLogger("test").info("messageDelivered:" + messageReference.toString());
super.messageDelivered(context,messageReference);
}
}
Thanks
解决方法
您还需要实现一个“ BrokerPlugin”对象,该对象是用于安装“ BrokerFilter”实例的类型。
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerPlugin;
public class MyPlugin implements BrokerPlugin {
public Broker installPlugin(Broker broker) throws Exception {
return new MyBroker(broker);
}
}
那将是您在代理XML配置中使用的类型
<plugins>
<bean xmlns="http://www.springframework.org/schema/beans" id="myPlugin" class="org.myorg.MyPlugin"/>
</plugins>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。