<?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"/>
...
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, for example:
Also copy the jar files you need to the Mule lib directory ($MULE_HOME/lib/user
) or your application lib directory.
Adding 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 JARs for External ActiveMQ apache-activemq-5.8.0/lib/activemq-client-5.8.0.jar JARs for Failover ActiveMQ apache-activemq-5.8.0/lib/activemq-client-5.8.0.jar To include these .jar files in your project, simply right-click on your project and select build path > add external archives. |
Mule initializes the ActiveMQ connector with a default instance of the ActiveMQ connection factory and establishes a TCP connection to the remote standalone broker running on the local host and listening on port 61616.
Use the failover protocol to connect to the cluster of brokers, and pass additional ActiveMQ options as URI parameters, for example:
<jms:activemq-xa-connector name="jmsFailoverConnector"
brokerURL="failover:(tcp://primary:61616,tcp://secondary:61616)?randomize=false"/>
To create an embedded instance of ActiveMQ broker, that is, broker running on the same Java VM as Mule, use vm protocol, for example:
<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, for example:
<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>
, for example:
<jms:activemq-connector name="jmsConnector" connectionFactory-ref="connectionFactory"/>
Debugging ActiveMQ
Debugging information for ActiveMQ can be enabled with the following log4j2 configuration. This provides debugging information on the REST queries sent between the connector and ActiveMQ service:
<AsyncLogger name="com.mulesoft.mq" level="DEBUG"/>
ActiveMQ Connector Reference
The activemq-connector element configures an ActiveMQ version of the JMS connector.
Attribute | Description |
---|---|
connectionFactory-ref |
Optional reference to the connection factory. A default connection factory is provided for vendor-specific JMS configurations. Type: string |
redeliveryHandlerFactory-ref |
Reference to the redelivery handler. Type: string |
acknowledgementMode |
The acknowledgement mode to use:
Type: enumeration |
clientId |
The ID of the JMS client. Type: string |
durable |
Whether to make all topic subscribers durable. Type: boolean |
noLocal |
If set to true, a subscriber does not receive messages that were published by its own connection. Type: boolean |
persistentDelivery |
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 the application may 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 message is persistent and if the destination has a sufficient message retention policy. Type: boolean |
honorQosHeaders |
If set to true, the message’s QoS headers are honored. If false (the default), the connector settings override the message headers. Type: boolean |
maxRedelivery |
The maximum number of times to try to redeliver a message. Use -1 to accept messages with any redelivery count. Type: integer |
cacheJmsSessions |
Whether to cache and re-use the JMS session object instead of recreating the connection each time. Note: This attribute is for non-transactional use ONLY. Type: boolean |
eagerConsumer |
Whether to create a consumer right when the connection is created instead of using lazy instantiation in the poll loop. Type: boolean |
specification |
The JMS specification to use: 1.0.2b (the default) or 1.1. Type: enumeration |
username |
The user name for the connection. Type: string |
password |
The password for the connection. Type: string |
numberOfConsumers |
The number of concurrent consumers that are used to receive JMS messages. (Note: If you use this attribute, you should not configure the Type: integer |
jndiInitialFactory |
The initial factory class to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
jndiProviderUrl |
The URL to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
jndiProviderProperties-ref |
Reference to a Map that contains additional provider properties. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
connectionFactoryJndiName |
The name to use when looking up the connection factory from JNDI. Type: string |
jndiDestinations |
Set this attribute to true if you want to look up queues or topics from JNDI instead of creating them from the session. Type: boolean |
forceJndiDestinations |
If set to true, Mule fails when a topic or queue cannot be retrieved from JNDI. If set to false, Mule creates a topic or queue from the JMS session if the JNDI lookup fails. Type: boolean |
disableTemporaryReplyToDestinations |
If this is set to false (the default), when Mule performs the request or response calls, a temporary destination is automatically set up to receive a response from the remote JMS call. Type: boolean |
embeddedMode |
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 Type: boolean |
brokerURL |
The URL used to connect to the JMS server. If not set, the default is Type: string |
Name |
Cardinality |
Description |
abstract-jndi-name-resolver |
0..1 |
A placeholder for jndi-name-resolver strategy elements. |
ActiveMQ XA Connector Reference
The activemq-xa-connector element configures an ActiveMQ version of the JMS connector with XA transaction support.
Attribute | Description |
---|---|
connectionFactory-ref |
Optional reference to the connection factory. A default connection factory is provided for vendor-specific JMS configurations. Type: string |
redeliveryHandlerFactory-ref |
Reference to the redelivery handler. Type: string |
acknowledgementMode |
The acknowledgement mode to use:
Type: enumeration |
clientId |
The ID of the JMS client. Type: string |
durable |
Whether to make all topic subscribers durable. If the durable attribute is set to true, then the clientId must be provided. Type: boolean |
noLocal |
If set to true, a subscriber does not receive messages that were published by its own connection. Type: boolean |
persistentDelivery |
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 the application may 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 message is persistent and if the destination has a sufficient message retention policy. Type: boolean |
honorQosHeaders |
If set to true, the message’s QoS headers are honored. If false (the default), the connector settings override the message headers. Type: boolean |
maxRedelivery |
The maximum number of times to try to redeliver a message. Use -1 to accept messages with any redelivery count. Type: integer |
cacheJmsSessions |
Whether to cache and re-use the JMS session object instead of recreating the connection each time. Note: This attribute is for non-transactional use ONLY. Type: boolean |
eagerConsumer |
Whether to create a consumer right when the connection is created instead of using lazy instantiation in the poll loop. Type: boolean |
specification |
The JMS specification to use: 1.0.2b (the default) or 1.1. Type: enumeration |
username |
The user name for the connection. Type: string |
password |
The password for the connection. Type: string |
numberOfConsumers |
The number of concurrent consumers that are used to receive JMS messages. (Note: If you use this attribute, you should not configure the Type: integer |
jndiInitialFactory |
The initial factory class to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
jndiProviderUrl |
The URL to use when connecting to JNDI. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
jndiProviderProperties-ref |
Reference to a Map that contains additional provider properties. DEPRECATED: use jndiNameResolver-ref property to configure this value. Type: string |
connectionFactoryJndiName |
The name to use when looking up the connection factory from JNDI. Type: string |
jndiDestinations |
Set this attribute to true if you want to look up queues or topics from JNDI instead of creating them from the session. Type: boolean |
forceJndiDestinations |
If set to true, Mule fails when a topic or queue cannot be retrieved from JNDI. If set to false, Mule creates a topic or queue from the JMS session if the JNDI lookup fails. Type: boolean |
disableTemporaryReplyToDestinations |
If this is set to false (the default), when Mule performs the request or response calls, a temporary destination is automatically set up to receive a response from the remote JMS call. Type: boolean |
embeddedMode |
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 Type: boolean |
brokerURL |
The URL used to connect to the JMS server. If not set, the default is Type: string |
Name |
Cardinality |
Description |
abstract-jndi-name-resolver |
0..1 |
A placeholder for jndi-name-resolver strategy elements. |