Most recently, I had the need to create a bridge from Topics to Queues in order to create stateless services. The goal was to adopt a model where messages can be processed in parallel. Essentially, I wanted to configure the following (in the message broker):
While there are many other ways to do this, I wanted to experiment with ActiveMQ to support this setup. 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):
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):
Now, I have the configuration in my conf
folder.
Configure ActiveMQ
Now that I have a mounted folder to the docker container (within the conf
folder), I can edit the activemq.xml
file so that the following is included in the virtualDestinations
section:
1
2
3
4
5
6
7
8
9
10
11
<destinationInterceptors>
<virtualDestinationInterceptor>
<virtualDestinations>
<compositeTopic name="t.example.service.event">
<forwardTo>
<queue physicalName="q.example.service.review" />
</forwardTo>
</compositeTopic>
</virtualDestinations>
</virtualDestinationInterceptor>
</destinationInterceptors>
The important lines here are the section where the compositeTopic
is configured to forward messages to the queue
. For a full example of the activemq.xml
file, please find it here.
Test: Send A 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.