Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

ActiveMQ Integration

Apache ActiveMQ is a popular open source messaging provider which is easy to integrate with Mule. ActiveMQ supports the JMS 1.1 and J2EE 1.4 specifications and is released under the Apache 2.0 License.

Usage

To configure ActiveMQ connector with most common settings, use <jms:activemq-connector> or <jms:activemq-xa-connector> (for XA transaction support) element in your Mule configuration, e.g:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8" ?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mule="http://www.mulesoft.org/schema/mule/core"
      xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
    xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
        http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.3/mule-jms.xsd">
 
  <jms:activemq-connector name="jmsConnector"
                          brokerURL="tcp://localhost:61616"/>
  <jms:activemq-xa-connector name="jmsXAConnector"
                             brokerURL="tcp://localhost:61616"/>
 
...

Also copy the jar files you need to the Mule lib directory ($MULE_HOME/lib/user) or your application lib directory.

Adding https://repository.apache.org/content/repositories/releases/org/apache/activemq/activemq-all/[ActiveMq-all.jar] will create conflicts with other dependencies, so please add only the jar files you need in relation to what you need ActiveMQ for:

apache-activemq-5.8.0/lib/activemq-kahadb-store-5.8.0.jar

apache-activemq-5.8.0/lib/activemq-protobuf-1.1.jar
apache-activemq-5.8.0/lib/activemq-openwire-legacy-5.8.0.jar
apache-activemq-5.8.0/lib/hawtbuf-1.9.jar
apache-activemq-5.8.0/lib/activemq-broker-5.8.0.jar
apache-activemq-5.8.0/lib/activemq-client-5.8.0.jar

apache-activemq-5.8.0/lib/activemq-client-5.8.0.jar
apache-activemq-5.8.0/lib/hawtbuf-1.9.jar

apache-activemq-5.8.0/lib/activemq-client-5.8.0.jar
apache-activemq-5.8.0/lib/hawtbuf-1.9.jar

To include these .jar files in your project, simply right-click on your project and select build path > add external archives.

Mule will initialize the ActiveMQ connector with default instance of ActiveMQ connection factory and establish a TCP connection to the remote standalone broker running on local host and listening on port 61616.

Use failover:// protocol to connect to the cluster of brokers, and pass additional ActiveMQ options as URI parameters, e.g.:


         
      
1
2
<jms:activemq-xa-connector name="jmsFailoverConnector"
     brokerURL="failover:(tcp://primary:61616,tcp://secondary:61616)?randomize=false"/>

To create an embedded instance of ActiveMQ broker, i.e. broker running on the same Java VM as Mule, use vm:// protocol, e.g.:


         
      
1
<jms:activemq-connector name="jmsConnector" brokerURL="vm://localhost"/>

You may also use additional connector attributes (See “Configuration Reference” for more details)

Sometimes it might be necessary to explicitly configure an instance of ActiveMQ connection factory, for example, to set redelivery policy, or other ActiveMQ-specific features that are not exposed through Mule connector parameters. To create custom ActiveMQ connection factory instance, first configure it using Spring, e.g.:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<bean name="connectionFactory"
     class="org.apache.activemq.ActiveMQConnectionFactory">
<!-- to support XA transactions, use org.apache.activemq.ActiveMQXAConnectionFactory instead -->
    <property name="brokerURL" 
              value="tcp://activemqserver:61616"/>
 
    <property name="redeliveryPolicy">
        <bean class="org.apache.activemq.RedeliveryPolicy">
            <property name="initialRedeliveryDelay"
                      value="20000"/>
            <property name="redeliveryDelay"
                      value="20000"/>
            <property name="maximumRedeliveries"
                      value="10"/>
       </bean>
    </property>
</bean>

then reference this bean in <jms:activemq-connector>, e.g.:


         
      
1
<jms:activemq-connector name="jmsConnector" connectionFactory-ref="connectionFactory"/>

Configuration Reference

The activemq-connector element configures an ActiveMQ version of the JMS connector.

The activemq-xa-connector element configures an ActiveMQ version of the JMS connector with XA transaction support.