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/current/mule.xsd
        http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/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:

JARs for Embedded ActiveMQ

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

JARs for External ActiveMQ

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

JARs for Failover ActiveMQ

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

Activemq connector

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

Table 1. Attributes of <activemq-connector…​>
Name Type Required Default Description

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

Allows Spring beans to be defined as a dispatcher pool factory

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

Allows Spring beans to be defined as a dispatcher pool factory

createMultipleTransactedReceivers

boolean

no

Whether to create multiple concurrent receivers for this connector. This property is used by transports that support transactions, specifically receivers that extend the TransactedPollingMessageReceiver, and provides better throughput.

numberOfConcurrentTransactedReceivers

integer

no

If createMultipleTransactedReceivers is set to true, the number of concurrent receivers that will be launched.

connectionFactory-ref

string

no

Optional reference to the connection factory. A default connection factory is provided for vendor-specific JMS configurations.

redeliveryHandlerFactory-ref

string

no

Reference to the redelivery handler.

acknowledgementMode

AUTO_ACKNOWLEDGE/CLIENT_ACKNOWLEDGE/DUPS_OK_ACKNOWLEDGE

no

AUTO_ACKNOWLEDGE

The acknowledgement mode to use: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, or DUPS_OK_ACKNOWLEDGE.

clientId

string

no

The ID of the JMS client.

durable

boolean

no

Whether to make all topic subscribers durable.

noLocal

boolean

no

If set to true, a subscriber will not receive messages that were published by its own connection.

persistentDelivery

boolean

no

If set to true, the JMS provider logs the message to stable storage as it is sent so that it can be recovered if delivery is unsuccessful. A client marks a message as persistent if it feels that the application will have problems if the message is lost in transit. A client marks a message as non-persistent if an occasional lost message is tolerable. Clients use delivery mode to tell a JMS provider how to balance message transport reliability/throughput. Delivery mode only covers the transport of the message to its destination. Retention of a message at the destination until its receipt is acknowledged is not guaranteed by a PERSISTENT delivery mode. Clients should assume that message retention policies are set administratively. Message retention policy governs the reliability of message delivery from destination to message consumer. For example, if a client’s message storage space is exhausted, some messages as defined by a site specific message retention policy may be dropped. A message is guaranteed to be delivered once-and-only-once by a JMS Provider if the delivery mode of the messge is persistent and if the destination has a sufficient message retention policy.

honorQosHeaders

boolean

no

If set to true, the message’s QoS headers are honored. If false (the default), the connector settings override the message headers.

maxRedelivery

integer

no

The maximum number of times to try to redeliver a message. Use -1 to accept messages with any redelivery count.

cacheJmsSessions

boolean

no

Whether to cache and re-use the JMS session object instead of recreating the connection each time. NOTE: meant for non-transactional use ONLY.

eagerConsumer

boolean

no

Whether to create a consumer right when the connection is created instead of using lazy instantiation in the poll loop.

specification

1.0.2b/1.1

no

1.0.2b

The JMS specification to use: 1.0.2b (the default) or 1.1

username

string

no

The user name for the connection

password

string

no

The password for the connection

numberOfConsumers

integer

no

The number of concurrent consumers that will be used to receive JMS messages. (Note: If you use this attribute, you should not configure the 'numberOfConcurrentTransactedReceivers', which has the same effect.)

jndiInitialFactory

string

no

The initial factory class to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

jndiProviderUrl

string

no

The URL to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

jndiProviderProperties-ref

string

no

Reference to a Map that contains additional provider properties. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

connectionFactoryJndiName

string

no

The name to use when looking up the connection factory from JNDI.

jndiDestinations

boolean

no

Set this attribute to true if you want to look up queues or topics from JNDI instead of creating them from the session.

forceJndiDestinations

boolean

no

If set to true, Mule fails when a topic or queue cannot be retrieved from JNDI. If set to false, Mule will create a topic or queue from the JMS session if the JNDI lookup fails.

disableTemporaryReplyToDestinations

boolean

no

If this is set to false (the default), when Mule performs request/response calls a temporary destination will automatically be set up to receive a response from the remote JMS call.

embeddedMode

boolean

no

false

Some application servers, like WebSphere AS, don’t allow certain methods to be called on JMS objects, effectively limiting available features. Embedded mode tells Mule to avoid those whenever possible. Default is false.

brokerURL

string

no

The URL used to connect to the JMS server. If not set, the default is vm://localhost?broker.persistent=false&broker.useJmx=false.

Child Elements of <activemq-connector…​>

Name Cardinality Description

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

abstract-jndi-name-resolver

0..1

A placeholder for jndi-name-resolver strategy elements.

Activemq xa connector

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

Attributes of <activemq-xa-connector…​>

Name Type Required Default Description

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

Allows Spring beans to be defined as a dispatcher pool factory

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

Allows Spring beans to be defined as a dispatcher pool factory

createMultipleTransactedReceivers

boolean

no

Whether to create multiple concurrent receivers for this connector. This property is used by transports that support transactions, specifically receivers that extend the TransactedPollingMessageReceiver, and provides better throughput.

numberOfConcurrentTransactedReceivers

integer

no

If createMultipleTransactedReceivers is set to true, the number of concurrent receivers that will be launched.

connectionFactory-ref

string

no

Optional reference to the connection factory. A default connection factory is provided for vendor-specific JMS configurations.

redeliveryHandlerFactory-ref

string

no

Reference to the redelivery handler.

acknowledgementMode

AUTO_ACKNOWLEDGE/CLIENT_ACKNOWLEDGE/DUPS_OK_ACKNOWLEDGE

no

AUTO_ACKNOWLEDGE

The acknowledgement mode to use: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, or DUPS_OK_ACKNOWLEDGE.

clientId

string

no

The ID of the JMS client.

durable

boolean

no

Whether to make all topic subscribers durable.

noLocal

boolean

no

If set to true, a subscriber will not receive messages that were published by its own connection.

persistentDelivery

boolean

no

If set to true, the JMS provider logs the message to stable storage as it is sent so that it can be recovered if delivery is unsuccessful. A client marks a message as persistent if it feels that the application will have problems if the message is lost in transit. A client marks a message as non-persistent if an occasional lost message is tolerable. Clients use delivery mode to tell a JMS provider how to balance message transport reliability/throughput. Delivery mode only covers the transport of the message to its destination. Retention of a message at the destination until its receipt is acknowledged is not guaranteed by a PERSISTENT delivery mode. Clients should assume that message retention policies are set administratively. Message retention policy governs the reliability of message delivery from destination to message consumer. For example, if a client’s message storage space is exhausted, some messages as defined by a site specific message retention policy may be dropped. A message is guaranteed to be delivered once-and-only-once by a JMS Provider if the delivery mode of the messge is persistent and if the destination has a sufficient message retention policy.

honorQosHeaders

boolean

no

If set to true, the message’s QoS headers are honored. If false (the default), the connector settings override the message headers.

maxRedelivery

integer

no

The maximum number of times to try to redeliver a message. Use -1 to accept messages with any redelivery count.

cacheJmsSessions

boolean

no

Whether to cache and re-use the JMS session object instead of recreating the connection each time. NOTE: meant for non-transactional use ONLY.

eagerConsumer

boolean

no

Whether to create a consumer right when the connection is created instead of using lazy instantiation in the poll loop.

specification

1.0.2b/1.1

no

1.0.2b

The JMS specification to use: 1.0.2b (the default) or 1.1

username

string

no

The user name for the connection

password

string

no

The password for the connection

numberOfConsumers

integer

no

The number of concurrent consumers that will be used to receive JMS messages. (Note: If you use this attribute, you should not configure the 'numberOfConcurrentTransactedReceivers', which has the same effect.)

jndiInitialFactory

string

no

The initial factory class to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

jndiProviderUrl

string

no

The URL to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

jndiProviderProperties-ref

string

no

Reference to a Map that contains additional provider properties. DEPRECATED: use jndiNameResolver-ref propertie to configure this value.

connectionFactoryJndiName

string

no

The name to use when looking up the connection factory from JNDI.

jndiDestinations

boolean

no

Set this attribute to true if you want to look up queues or topics from JNDI instead of creating them from the session.

forceJndiDestinations

boolean

no

If set to true, Mule fails when a topic or queue cannot be retrieved from JNDI. If set to false, Mule will create a topic or queue from the JMS session if the JNDI lookup fails.

disableTemporaryReplyToDestinations

boolean

no

If this is set to false (the default), when Mule performs request/response calls a temporary destination will automatically be set up to receive a response from the remote JMS call.

embeddedMode

boolean

no

false

Some application servers, like WebSphere AS, don’t allow certain methods to be called on JMS objects, effectively limiting available features. Embedded mode tells Mule to avoid those whenever possible. Default is false.

brokerURL

string

no

The URL used to connect to the JMS server. If not set, the default is vm://localhost?broker.persistent=false&broker.useJmx=false.

Child Elements of <activemq-xa-connector…​>

Name Cardinality Description

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

annotations

0..1

 

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

abstract-jndi-name-resolver

0..1

A placeholder for jndi-name-resolver strategy elements.