如何启用activemq插件

huangapple go评论79阅读模式
英文:

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 | INFO | Created LoggingBrokerPlugin: LoggingBrokerPlugin(logAll=true, logConnectionEvents=true, logSessionEvents=true, logConsumerEvents=false, logProducerEvents=false, logTransactionEvents=false, logInternalEvents=false)

但是没有关于我的插件的任何信息...
如何注册和启用我的插件?

以下是你提供的Java代码:

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);
    }
}

希望这些信息对你有帮助。

英文:

I'm trying to create an interceptor for activemq (5.15.13).
I use code from https://activemq.apache.org/interceptors and compile it as jar file.
I added jar file to <ACTIVEMQ>/lib folder.

Then I added to activemq.xml

&lt;plugins&gt;
			&lt;loggingBrokerPlugin logAll=&quot;true&quot; logConnectionEvents=&quot;true&quot;/&gt;
			&lt;bean xmlns=&quot;http://www.springframework.org/schema/beans&quot; id=&quot;myPlugin&quot; class=&quot;com.xxx.mqplugin.MyPlugin&quot;/&gt;
&lt;/plugins&gt;

I see

> jvm 1 | INFO | Created 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(&quot;addConnection:&quot; + info.toString());
		Logger.getLogger(&quot;test&quot;).info(&quot;addConnection:&quot; + 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(&quot;addSession:&quot; + info.toString());
		Logger.getLogger(&quot;test&quot;).info(&quot;addSession:&quot; + 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(&quot;addProducer:&quot; + info.toString());
		Logger.getLogger(&quot;test&quot;).info(&quot;addProducer:&quot; + info.toString());

		super.addProducer(context, info);
	}
	
	@Override
    public void messageDelivered(ConnectionContext context,MessageReference messageReference) {
        
        
        System.out.println(&quot;messageDelivered:&quot; + messageReference.toString());
		Logger.getLogger(&quot;test&quot;).info(&quot;messageDelivered:&quot; + messageReference.toString());

		super.messageDelivered(context, messageReference);
    }
}

Thanks

</details>


# 答案1
**得分**: 1

```java
需要实现一个名为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>
英文:

You need to implement a "BrokerPlugin" object as well which is the type that is used to install your "BrokerFilter" instance.

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

  &lt;plugins&gt;
&lt;bean xmlns=&quot;http://www.springframework.org/schema/beans&quot; id=&quot;myPlugin&quot; class=&quot;org.myorg.MyPlugin&quot;/&gt;    
&lt;/plugins&gt;

huangapple
  • 本文由 发表于 2020年8月20日 17:37:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63502306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定