英文:
How to enable activemq plugin
问题
我正在尝试为activemq(5.15.13)创建拦截器。
我使用来自https://activemq.apache.org/interceptors的代码,并将其编译为jar文件。
我将jar文件添加到
然后我在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
<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 | 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("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
</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
<plugins>
<bean xmlns="http://www.springframework.org/schema/beans" id="myPlugin" class="org.myorg.MyPlugin"/>
</plugins>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论