Tuesday, December 3, 2019

ActiveMQ: Bridging Topics to Queues

Most recently, I had the need to create a bridge from Topics to Queues to create stateless services that can pick up messages in parallel. Essentially, I wanted to configure the following (in the message broker):

Topic to Queue Bridge
While there are many other ways to do this, I wanted to experiment with ActiveMQ support for this. The following is how I configured it locally (in my dev box):

Use a Docker Image
I used an ActiveMQ docker image found here. It was pretty straightforward and was able to get it running after a few commands. Here is what I did to define a baseline (this is from the instructions in the link above):
  docker run --user root --rm -ti \
  -v /Users/alberto/workspace/docker/activemq/conf:/mnt/conf \
  -v /Users/alberto/workspace/docker/activemq/data:/mnt/data \
  rmohr/activemq:5.15.4-alpine /bin/sh

Notice the following:

  • I created the /conf and /data directory in my dev box.
  • I mounted these folders into the /mnt/* respective to my local box.
  • As the end of this command, a shell will be started inside the docker container
Then, I had to do the following (within the docker container):
  chown activemq:activemq /mnt/conf
chown activemq:activemq /mnt/data
cp -a /opt/activemq/conf/* /mnt/conf/
cp -a /opt/activemq/data/* /mnt/data/
exit

Now, I have the configuration in my "conf" folder.

Configure ActiveMQ
Within the "conf" folder, we need to edit the activemq.xml file.

The important lines here are from 125 to 136 where I use "VirtualDestinations".

Test Message Forward
You can now go to the admin console at:

  http://localhost:8161/admin/send.jsp

and send a message to the topic. You will see messages forwarded to the queues of your choice.

No comments: