[英]How to enable activemq plugin
我正在嘗試為 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”object,這是用於安裝“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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.