Dynamic failover combines the failover protocol and a network of brokers to allow a broker to supply its clients with a list of broker connections to which the clients can failover. Clients use a failover URI to connect to a broker and the broker dynamically updates the clients' list of available URIs. The broker updates its clients' failover lists with the URIs of the other brokers in its network of brokers that are currently running. As new brokers join, or exit, the cluster, the broker will adjust its clients' failover lists.
From a connectivity point of view, dynamic failover works the same as static failover. A client randomly chooses a URI from the list provided in its failover URI. Once that connection is established, the list of available brokers is updated. If the original connection fails, the client will randomly select a new URI from its dynamically generated list of brokers. If the new broker is configured for dynamic failover, the new broker will update the client's list.
To use dynamic failover you must configure both the clients and brokers used by your application. The following must be configured:
The client's must be configured to use the failover protocol when connecting with its broker.
The brokers must be configured to form a network of brokers.
See Broker Networks in Clustering Guide.
The broker's transport connector must set the failover properties needed to update its consumers.
The client-side configuration for using dynamic failover is identical to the client-side configuration for using static failover. The client uses a failover URI to connect to a broker.
When using dynamic failover, the failover URI can include a single broker URI. As long as the broker is available when the client attempts to make its initial connection, the client's list of failover brokers will get populated.
It is also important that the updateURIsSupported
option not be set to
false
. If it is, the client will not be able to receive updates about what
brokers are available for failover.
See Failover URI and Transport options for more information about using failover URIs.
Configuring a broker to participate in dynamic failover requires two things:
The broker must be configured to participate in a network of brokers that can be available for failovers.
See Broker Networks in Clustering Guide for information about setting up a network of brokers.
The broker's transport connector must set the failover properties needed to update its consumers.
Table 6.2 describes the broker-side properties
that can be used to configure a failover cluster. These properties are attributes on the
broker's transportConnector
element.
Table 6.2. Broker-side Failover Properties
Example 6.2 shows the configuration for a broker that participates in dynamic failover.
Example 6.2. Broker for Dynamic Failover
<beans ... > <broker> ... <networkConnectors><networkConnector uri="multicast://default" /> </networkConnectors> ... <transportConnectors> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"
discoveryUri="multicast://default"
updateClusterClients="true"
updateClusterFilter="*A*,*B*" /> </transportConnectors> ... </broker> </beans>
The configuration in Example 6.2 does the following:
Creates a network connector that connects to any discoverable broker that uses the multicast transport. | ||||
Makes the broker discoverable by other brokers over the multicast protocol. | ||||
Makes the broker update the list of available brokers for clients that connect using the failover protocol.
| ||||
Creates a filter so that only those brokers whose names start with the letter
|
Example 6.3 shows the URI for a client that uses the failover protocol to connect to the broker and its cluster.
Example 6.3. Failover URI for Connecting to a Failover Cluster
failover://(tcp://0.0.0.0:61616)?initialReconnectDelay=100