简体   繁体   中英

ActiveMQ failover stays on second URL

So I have this connection to a ActiveMQ Artemis 2.19.1 cluster using java code

String brokerUrl = "failover:(tcp://10.5.1.1:61616,tcp://10.6.1.2:61617)?nested.connectionTimeout=1000&randomize=false&maxReconnectAttempts=0&maxReconnectDelay=1000";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);

I observe that when the first node is down it connects successfully to the second node, but every time my producer sends a message it has a 1 second delay because it tries to connect to the first node every time. Is there a way to configure the connection to keep using the last successful node instead of always trying the first one. I don't see any reference in the documentation for this behavior that I'm looking for.

I don't want to lower the timeout values from fear of it failing to connect to a working node, and I don't think that that should be the right approach.

Also when the first node comes online it will automatically connect to the first node instead of keeping the connection to the second node

Based on your description it sounds like your producer is creating a new connection every time it sends a message. If that is the case then that is almost certainly the problem here, and it is also a very well-known anti-pattern that you should avoid whenever possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM