user983141
user983141

Reputation: 61

Switching back to the primary remote broker after successful failover

We are using Apache ActiveMQ 5.5. We have a broker (let us call it Main Broker) running at tcp://0.0.0.0:61616. This broker does a store and forward message to a remote broker. To do that, we have a network connection from this broker to two remote brokers. We want one of the remote brokers to serve as primary and other as failover. This is the network connect URI that we are using

static:(failover://(tcp://<b>server1</b>:61617,tcp://<b>server2</b>:61617)?randomize=false)

We are using spring DefaultMessageListenerContainer to listen for the messages

failover://(tcp://<b>server1</b>:61617,tcp://<b>server2</b>:61617)?randomize=false

In the normal scenario when all the brokers are up and running and a message is sent to Main Broker, it is getting forwarded to server1 and is consumed by the listener.

If we stop the broker on server1, the fail over is happening successfully and the messages are getting forwarded to server2 and successfully consumed by the listener. The problem is when we bring the server1 back up, the messages continue to be forwarded by the main broker to server2. Our requirement is that once the server1 is up and running, the Main broker should start forwarding the messages to server1 and the listener should connect back to server1 and consume messages. We cannot change randomize to true because we want only one of the servers1 or server2 to be active at a time.

Please let me know whether it is possible and how.

Upvotes: 4

Views: 1389

Answers (1)

anon
anon

Reputation:

You need to set to true the option "priorityBackup". You URI will become:

static:(failover://(tcp://server1:61617,tcp://server2:61617)?randomize=false&priorityBackup=true)

This will make server1 (the first in the list of servers) priority backup. When server1 goes down, he will failover to server2, but constantly try to reconnect to server1. Hence, when it goes back up again, he will switch back to server1. This option is only available in version 5.6

The complete details are here: http://activemq.apache.org/failover-transport-reference.html

There is also an interesting blog here: http://bsnyderblog.blogspot.com/2010/10/new-features-in-activemq-54-automatic.html

Upvotes: 4

Related Questions