The Failover TransportThe Failover transport layers reconnect logic on top of any of the other transports. (We used to call this transport the Reliable transport in ActiveMQ 3). The Failover configuration syntax allows you to specify any number of composite uris. The Failover transport randomly chooses one of the composite URI and attempts to establish a connection to it. If it does not succeed or if it subsequently fails, a new connection is established to one of the other uris in the list. Configuration Syntaxfailover:(uri1,...,uriN)?transportOptions The failover transport uses random by default which lets you to load balance clients over a number of brokers. If you would rather connect to a primary first and only connect to a secondary backup broker if the primary is unavailable, turn off randomizing using something like failover:(tcp://primary:61616,tcp://secondary:61616)?randomize=false Transport Options
Example URIfailover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100 If the above gives errors try it this way (this way works in ActiveMQ 4.1.1 the one above does not) failover://(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100 NotesIf you use failover, and a broker dies at some point, your sends will block by default. Using TransportListener can help with this regard. It is best to set the Listener directly on the ActiveMQConnectionFactory so that it is in place before any request that may require an network hop. failover:(tcp://primary:61616)?timeout=3000 will cause send to fail after 3 seconds if the connection isn't established. The connection will not be killed, so you can try sending messages later at some point using the same connection (presumably some of your brokers will be available again). Timeouts on the failover transport are available since 5.3 version. TransactionsThe Failover transport tracks transactions by default. The inflight transactions are replayed on reconnection. For simple scenarios this works ok. However there is an assumption for acknowledged (or consumer) transactions, that the previously received messages will get relayed after a reconnect. This is not always true when there are many connections and consumers, as redelivery order is not guaranteed. It is possible to have stale outstanding acknowledgements that can interfere with newly delivered messages, potentially leading to unacknowledged messages. Broker side Options for FailoverThis is new in version 5.4: There are some options that are available on a TransportConnector that is used by the broker that can be used to update clients automatically with information about new brokers to failover to. These are:
An example as defined within the broker's XML configuration file: <broker> ... <transportConnectors> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" updateClusterClients="true" updateClusterFilter="*A*,*B*" /> </<transportConnectors> ... </broker> If updateClusterClients is enabled, then your clients will only need to know about the first broker to connect to in a cluster of brokers - e.g.: failover://tcp://primary:61616 If new brokers join, the client will automatically be updated with the additional URI of that broker to connect to in the event of a network or broker failure. More InformationAlso check out the following blog entry about using the cluster client updates and rebalancing features titled New Features in ActiveMQ 5.4: Automatic Cluster Update and Rebalance. |
|