2017-10-30

Getting Discovery Groups to Work Locally in Artemis

This is less a detailed post and more a PSA for setting up Apache ActiveMQ Artemis on your local machine. Specifically, if you're trying (and failing) to get Discovery Groups to work. Hopefully it saves someone out there a sleepless night or two 😀

Artemis Discovery Groups let one cluster brokers in a way that is more dynamic than manually cobbling them together using explicit IPs or hostnames. This then opens up the possibility of being able to more fluidly change your network topology rather than having to "rewire" the servers everytime something changes.

Excited?! So was I when I decided to download this example, and see discovery in action. So I set it up and ... nothing worked. The brokers couldn't find each other, no cluster, unhappy days. So what gives?

Well, one of the ways Artemis does discovery is to broadcast group information using UDP out to anyone that may be interested. This is fine when you have several distinct machines all listening for traffic, but it won't work if both brokers are on the same machine because it generally doesn't make sense for a device to listen to its own traffic. So how do we make our machine talk to itself (besides reducing its dose of anti-psychotic medication)? Simple, following this guide, you set your chosen discovery multicast address to be looped back.

#you should run this as root
route add -net 224.0.0.0 netmask 240.0.0.0 dev lo

How Do I Know It Worked?

If you've configured your cluster correctly, and enabled the loop-back described above, then you should see the brokers in your cluster log something similar to the following:

(...other logs...)

14:21:32,104 INFO  [org.apache.activemq.artemis.core.server] AMQ221027: Bridge ClusterConnectionBridge@27cc737b [name=$.artemis.internal.sf.my-cluster.e3a0a8ca-b3bc-11e7-a812-28b2bddf2e01, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.e3a0a8ca-b3bc-11e7-a812-28b2bddf2e01, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=69705a0c-b3b6-11e7-b87c-28b2bddf2e01], temp=false]@634dabfa targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@27cc737b [name=$.artemis.internal.sf.my-cluster.e3a0a8ca-b3bc-11e7-a812-28b2bddf2e01, queue=QueueImpl[name=$.artemis.internal.sf.my-cluster.e3a0a8ca-b3bc-11e7-a812-28b2bddf2e01, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::serverUUID=69705a0c-b3b6-11e7-b87c-28b2bddf2e01], temp=false]@634dabfa targetConnector=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=netty-connector, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=0-0-0-0], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@555273695[nodeUUID=69705a0c-b3b6-11e7-b87c-28b2bddf2e01, connector=TransportConfiguration(name=netty-connector, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61617&host=0-0-0-0, address=example, server=ActiveMQServerImpl::serverUUID=69705a0c-b3b6-11e7-b87c-28b2bddf2e01])) [initialConnectors=[TransportConfiguration(name=netty-connector, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=0-0-0-0], discoveryGroupConfiguration=null]] is connected

(...more logs...)