如何启用activemq插件

ubbxdtey  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(451)

我正在尝试为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 | info |创建了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
s8vozzvw

s8vozzvw1#

您还需要实现一个“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);
        }   

}

这就是您在brokerxml配置中使用的类型

<plugins>
      <bean xmlns="http://www.springframework.org/schema/beans" id="myPlugin" class="org.myorg.MyPlugin"/>    
  </plugins>

相关问题