1.3. Integrating with an ActiveMQ Failover Cluster

Overview

This section describes how to configure the ActiveMQ resource adapter to connect to an ActiveMQ failover cluster (for example, a high-availability master/slave cluster). For details about how to set up and configure such a cluster, see "Fault Tolerant Messaging".

Failover URL

To connect to a cluster of JBoss A-MQ brokers (for example, a master/slave pair of brokers), you need to configure the ServerUrl configuration property with a failover URL, which lists the available endpoints in the cluster. The general form of the failover URL you should use is as follows:
failover:(uri1,...,uriN)?maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
Note
It is important to set the options as shown, in order to ensure a clean cutover when the master fails in a master/slave high-availability cluster. You do not want a failover client to attempt reconnection to the same endpoint. The client should always try the next URI in the failover list.

Sample scenario

Consider the scenario where a broker running on host amqhostA and a broker running on host amqhostB are configured to run as a high-availability master/slave cluster. In this scenario, the brokers expose the following TCP endpoints:
tcp://amqhostA:61616
tcp://amqhostB:61616
To connect to this cluster, the resource adapter should be configured with the following failover URL:
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
When setting the URL in an XML file, you must remember to escape the & symbol as & giving the URL:
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false

Configuring the ActiveMQ resource adapter for failover

To configure the ActiveMQ resource adapter to connect to an ActiveMQ failover cluster, you must modify the following configuration settings:
  • Set the ServerUrl configuration property to a correctly configured failover URL,
  • Set the UseInboundSession configuration property to true for inbound connections (set as the direct child of the resource-adapter element), and
  • Set the UseInboundSession configuration property to false for the connection factories (set as the child of a connection-definition element).
Open the EAPInstallDir/standalone/configuration/standalone-full.xml file using a text editor, search for the urn:jboss:domain:resource-adapters:1.1 subsystem, and modify the ServerUrl property and the UseInboundSession property as shown in Example 1.3, “ActiveMQ Resource Adapter Configuration for Failover”. You will need to customize the value of the failover URL, as appropriate, to match the configuration of your broker cluster.

Example 1.3. ActiveMQ Resource Adapter Configuration for Failover

<server xmlns="urn:jboss:domain:1.4">
    ...
    <profile>
        ...
        <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
            <resource-adapters>
                <resource-adapter id="activemq-rar.rar">
                    ...
                    <config-property name="ServerUrl">
                        failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&amp;maxReconnectAttempts=0
                    </config-property>
                    ...
                    <config-property name="UseInboundSession">
                        true
                    </config-property>
                    ...
                    <connection-definitions>
                        <connection-definition ... >
                            ...
                            <config-property name="UseInboundSession">
                                false
                            </config-property>
                            ...
                        </connection-definition>
                    </connection-definitions>
                    ...
                </resource-adapter>
                ...
            </resource-adapters>
        </subsystem>
        ...
    </profile>
    ...
</server>