Transition to the main remote broker after a successful transition to another resource

We are using Apache ActiveMQ 5.5. We have a broker (let's call it the main broker) that runs on tcp: //0.0.0.0: 61616. This broker sends and sends a message to a remote broker. To do this, we have a network connection from this broker to two remote brokers. We want one of the remote brokers to serve as the primary and the other to be fault tolerant. This is the URI of the network connection that we are using

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

We use spring DefaultMessageListenerContainer to listen for messages

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

In the usual scenario, when all brokers are started and a message is sent to the main broker, it is sent to server1 and consumed by the listener.

If we stop the broker on server1, the failure will succeed, and messages will be sent to server2 and successfully used by the listener. The problem is that when we return server 1, messages continue to be forwarded by the main broker to server2. Our requirement is that as soon as server 1 is up and running, the Main Broker should start sending messages to server1, and the listener should connect to server1 and use messages. We cannot change randomize to true because we want only one of server1 or server2 to be active at a time.

Please let me know if and how.

+4
source share
1 answer

You need to set true to "priorityBackup". You will get a URI:

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

This will prioritize the backup server server1 (first in the list of servers). When server 1 goes down, it will go to server2, but is constantly trying to connect to server1. Therefore, when he returns again, he will switch to server1. This option is available only in version 5.6.

Full details 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

+4
source

Source: https://habr.com/ru/post/1390337/


All Articles