Developing Plugins

Developers > Developer Guide > Developing Plugins

Apache ActiveMQ Classic is based on the model of POJOs and Dependency Injection. If you are developing Interceptors or additional components or plugins for ActiveMQ Classic then the first thing you should do is develop the code as if you are writing any other Spring component, using dependency injection.

Dependency Injection

Some folks favour using constructor based injection as it removes the need to have a separate lifecycle start() method - others find using property based injection is a little more flexible and easier to map to XML configuration files. We’ll leave that choice up to you. For complex to create objects you could consider writing a FactoryBean. For more details on writing POJOs with Spring see their documentation.

Custom XML

With ActiveMQ Classic you can use regular Spring.xml syntax to configure things. However to produce neater XML that is easier to read and edit we use XBean to autogenerate support for Custom XML.

If you wish your POJO to have its own custom XML you may wish to follow the following source examples for working nicely with XBean. Basically you add an XBean annotation in the javadoc comments to tell XBean how to map the POJO to custom XML. This should look something like

/**
 * @org.apache.xbean.XBean element="foo"
 */
public class MyExtension {
...
}

You can omit the element configuration. For more details on the available annotation options see here

If you are submitting your plugin to the ActiveMQ Classic project then it will end up being included in the maven build step to create the XBean artifacts as part of the jar (in the META-INF/services area).

However if you are writing an external plugin to ActiveMQ Classic then you will need to add the maven-xbean-plugin to your Maven 2 build. Refer to the activemq-spring/pom.xml as an example of using this plugin.

Configuring plugins without custom XML

If you want to configure plugins that does not implement custom XML, you can define plugins as “regular” Spring beans and reference them in broker’s plugins attribute. For example,

<broker useJmx="true" xmlns="http://activemq.apache.org/schema/core" plugins="#loggingPlugin">
 ...
</broker>

<bean id="loggingPlugin" 
      class="org.apache.activemq.broker.util.LoggingBrokerPlugin"
/>

Not that this mechanism will not work in case that you have some XBean plugins configured inside the <plugins/> tag. In that case you must define the plugin inside that tag as well (with the appropriate schema definition). For example,

<plugins>
    <simpleAuthenticationPlugin>
      <users>
        <authenticationUser username="system" password="manager"
          groups="users,admins"/>
        <authenticationUser username="user" password="password"
          groups="users"/>
        <authenticationUser username="guest" password="password" groups="guests"/>
      </users>
    </simpleAuthenticationPlugin>  
    <bean xmlns="http://www.springframework.org/schema/beans" 
          id="loggingPlugin" 
          class="org.apache.activemq.broker.util.LoggingBrokerPlugin"
    />
</plugins>  

Examples

The easiest way to get a feel for how to extend ActiveMQ Classic is maybe to look at some concrete examples of features and how those are implemented and configured. Here are some examples

Apache, ActiveMQ, Apache ActiveMQ, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. Copyright © 2024, The Apache Software Foundation. Licensed under Apache License 2.0.