1
votes

I have an Artemis brokers cluster with two master and two slave brokers. I am trying to push messages to this cluster programmatically. I understand with only one broker the brokerUrl to set in ActiveMQConnectionFactory.setBrokerUrl(String brokerURL) would be tcp://10.10.100.217:61616.

Now, I have a cluster with two master and two slave brokers so in that case what would be the brokerURL? The group-address in broker.xml is 231.7.7.7.

1

1 Answers

1
votes

There's a couple of ways you can deal with this.

First, you can just add all the hosts and ports to the URL, e.g.:

(tcp://master1:61616,tcp://slave1:61616,tcp://master2:61616,tcp://slave2:61616)

When a core client connects to a master it will automatically be informed of any backup, but you can't guarantee that one of the predefined masters will actually be up so it's safest to just list all the brokers in the URL.

Second, you can use discovery from the client, e.g.:

udp://231.7.7.7:9876

Here the client uses the same UDP multicast address and port that the brokers use to form the cluster. The client will listen on this multicast address & port to discover which brokers are up and then connect to one of them.

Of course for this to work UDP multicast packets must be able to reach the client from the broker and that typically means they have to be on the same network subnet as UDP multicast is typically not broadcast beyond this.