Reputation: 1
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 /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
Upvotes: 0
Views: 548
Reputation: 18356
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>
Upvotes: 1