ActiveMQ failover connection not working but works with single IP

47 Views Asked by At

I'm new to Java and writing a microservice that connects to an ActiveMQ cluster. I can connect to the cluster and read messages successfully when I use one single broker IP address. However, the connection doesn't work when I pass all IP's as a failover config.

Working config:

    private static String url = "tcp://1.2.3.4:61616";
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    connectionFactory.setUserName("abc@abc");
    connectionFactory.setPassword("abc");
    connectionFactory.setClientID("testingClient");

Failed config:

    private static String url = "failover://(tcp://1.2.2.4:61616,tcp://17.3.2.50:61616,tcp://14.3.8.6:61616,tcp://2.3.0.4:61616,tcp://7.2.2.5:61616,tcp://32.33.1.6:61616)?randomize=false";
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
    connectionFactory.setUserName("abc@abc");
    connectionFactory.setPassword("abc");
    connectionFactory.setClientID("testingClient"); 
1

There are 1 best solutions below

1
Justin Bertram On

It appears you have an extra // in the failover URL. Try using this instead:

private static String url = "failover:(tcp://1.2.2.4:61616,tcp://17.3.2.50:61616,tcp://14.3.8.6:61616,tcp://2.3.0.4:61616,tcp://7.2.2.5:61616,tcp://32.33.1.6:61616)?randomize=false";