简体   繁体   English

如何启用 activemq 插件

[英]How to enable activemq plugin

I'm trying to create an interceptor for activemq (5.15.13).我正在尝试为 activemq (5.15.13) 创建一个拦截器。 I use code from https://activemq.apache.org/interceptors and compile it as jar file.我使用来自https://activemq.apache.org/interceptors的代码并将其编译为 jar 文件。 I added jar file to /lib folder.我将 jar 文件添加到 /lib 文件夹。

Then I added to activemq.xml然后我添加到activemq.xml

<plugins>
            <loggingBrokerPlugin logAll="true" logConnectionEvents="true"/>
            <bean xmlns="http://www.springframework.org/schema/beans" id="myPlugin" class="com.xxx.mqplugin.MyPlugin"/>
</plugins>

I see我懂了

jvm 1 | jvm 1 | INFO |信息 | Created LoggingBrokerPlugin: LoggingBrokerPlugin(logAll=true, logConnectionEvents=true, logSessionEvents=true, logConsumerEvents=false, logProducerEvents=false, logTransactionEvents=false, logInternalEvents=false)创建的 LoggingBrokerPlugin:LoggingBrokerPlugin(logAll=true,logConnectionEvents=true,logSessionEvents=true,logConsumerEvents=false,logProducerEvents=false,logTransactionEvents=false,logInternalEvents=false)

But nothing about my plugin.. How to register and enable my plugin?但是关于我的插件一无所知。如何注册和启用我的插件?

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

You need to implement a "BrokerPlugin" object as well which is the type that is used to install your "BrokerFilter" instance.您还需要实施“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);
        }   

}

That would then be the type you use in the broker XML configuration那就是您在代理 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM