Apache ActiveMQ ™ -- Interceptors

Features > Interceptors

ActiveMQ has a sophisticated interceptor stack so that you can attach whatever functionality you require into the broker in an easy way without complicating all of the other broker code. This has really helped us keep the code clean and modular while offering powerful extension points.

For an example of the kinds of things you can do with interceptors see the following pages

How plugins work

A plugin is an instance of the interface BrokerPlugin which allows a plugin to add itself into the broker interceptor chain, typically using the BrokerFilter as a base class to allow only certain operations to be customized.

The object that implements the BrokerPlugin interface is called out as a plugin in the message broker's XML configuration file (see example below). Your plugin can then optionally reference other beans that are defined in the XML file.

foo foo2

You can also define plugins from within the element as this example illustrates.

At startup, the main or core broker calls your plugin's installPlugin() method. This method creates and returns an object that typically extends 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);
    }    

}

The BrokerFilter class is a convenience class that implements the Broker interface. This interface defines all the main operations (e.g., addConnection, addSession, etc.) that your implementation can intercept. The class that extends BrokerFilter overrides any of the methods that are defined in the Broker interface so that it can intercept the corresponding core engine's operations. Here's an example of a class that extends BrokerFilter and intercepts/overrides the addConnection() and addSession() Broker methods/operations.

import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.BrokerFilter; import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.command.ConnectionInfo;

public class MyBroker extends BrokerFilter {

 public MyBroker(Broker next) {
    super(next);                
}

public void addConnection(ConnectionContext context, ConnectionInfo info) 
        throws Exception {       

     // Your code goes here 

    // Then call your parent
    super.addConnection(context, info);
}   

public void addSession(ConnectionContext context, SessionInfo info) 
        throws Exception {       

     //  Your code goes here...

     // Then call your parent
     super.addSession(context, info);
}    

}

For more details see Developing Plugins

results matching ""

    No results matching ""