There are 2 servers (amq1, amq2) with ActiveMQ deployed. The service that creates the queues is on the third server.

in the connection settings, I specified spring.activemq.broker-url: failover:(ssl://amq1:61616,ssl://amq1:61616)

Both servers work correctly and do not lose connection.

The problem is that the service first connects to amq1 in priority, but sometimes it changes the connection to amq2, then returns to the first one. There is no message in the logs that the connection to amq1 is missing.

 INFO 24003 --- [ActiveMQ Task-1] oaatfailover.FailoverTransport : Successfully connected to ssl://amq2:61616 INFO 24003 --- [ActiveMQ Task-1] oaatfailover.FailoverTransport : Successfully connected to ssl://amq2:61616 INFO 24003 --- [ActiveMQ Task-1] oaatfailover.FailoverTransport : Successfully connected to ssl://amq1:61616 ERROR 24003 --- [http-nio-127.0.0.1-8080-exec-4] roRestExceptionHandler : dm.exception.ActiveMQException: Failed get JMS response: INFO 24003 --- [ActiveMQ Task-1] oaatfailover.FailoverTransport : Successfully connected to ssl://amq2:61616 INFO 24003 --- [ActiveMQ Task-1] oaatfailover.FailoverTransport : Successfully connected to ssl://amq1:61616 

How can I make the connection to amq2 only if amq1 stops responding?

ps if you specify only one amq server, then when the connection is lost, spring 10 times by default tries to reconnect. I would like to change the connection to amq2 after 10 times

    1 answer 1

    do you need to add a failover:(ssl://amq1:61616,ssl://amq1:61616)?randomize=false&priorityBackup=true to the connection failover:(ssl://amq1:61616,ssl://amq1:61616)?randomize=false&priorityBackup=true

    in short, "use priority in order, always reconnect if broker is available"

    from the documentation follows

    priorityBackup = true

    This is a link to the local broker. If local broker fails However, as a priority parameter, the client will be used. If you need to do this, you will need to do so.

    randomize = false

    The Failover transport chooses a URI at random by default. This effectively load-balances clients over multiple brokers. However, there is no need for a secondary backup broker when it is unavailable, set randomize = false.