Enterprise Java

ActiveMQ – Network of Brokers Explained – Part 2

In this blog we will see how duplex network connectors work.

In the previous part 1 we created a network connector from broker-1 and broker-2. We were able to see how messages for queue “foo.bar” on broker-1 were forwarded queue “foo.bar” on broker-2 when there was a consumer on broker-2 for queue “foo.bar”

Let’s try doing the reverse by producing messages into broker-2’s queue foo.bar and consume from broker-1’s queue “foo.bar”


Ashwinis-MacBook-Pro:example akuntamukkala$ ant producer -Durl=tcp://localhost:61626 -Dtopic=false -Ddurable=true -Dsubject=foo.bar -Dmax=100
Ashwinis-MacBook-Pro:example akuntamukkala$ ant consumer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar


In the previous blog post, we had enqueued/dequeued 100 messages. Hence the #messages enqueued now shows as 200 here.

As shown above, 100 new messages are enqueued on foo.bar queue on broker-2 but there are no consumers though there is a network connector for all queues from broker-1 to broker-2.

The reason is that a network connector unless specified as “duplex” is unidirectional from the source to the destination broker. 

Let’s change the following attribute highlighted in yellow in

 /Users/akuntamukkala/apache-activemq- 5.8.0/bridge-demo/broker-1/conf/activemq.xml

configuration file for broker-1.

                  <queue physicalName=">" />
                  <topic physicalName=">" />

Let’s restart the brokers and connect to the brokers using jConsole.

Here is broker-1 jConsole MBean tab screenshot which shows the following:

  1. Q:broker1->broker2 network connector is duplex.
  2. There is now a dynamic producer into broker-1 from broker-2 because the
    Q:broker1->broker2 network connector is “duplex”.


Here is broker-2 jConsole MBean tab screenshot which shows the following:

  1. Duplex network connector from broker-2 to broker-1
  2. Two dynamic message producers from broker-1 to broker-2
    1. Please note that “Q:broker1->broker2” network connector shows as duplex as configured in activemq.xml


Let’s see this in action

  1. Producer 100 messages into broker-2
  2. Ashwinis-MacBook-Pro:example akuntamukkala$ ant producer -Durl=tcp://localhost:61626 -Dtopic=false -Ddurable=true -Dsubject=foo.bar -Dmax=100

    Screenshot of queues in broker-2: http://localhost:9161/admin/queues.jsp


  3. Create a consumer on foo.bar on broker-1
  4. Ashwinis-MacBook-Pro:example akuntamukkala$ ant consumer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar

    The following screenshot from broker-2 shows that all the 100 messages have been dequeued by a consumer (dynamically forwarded to broker-1).



    The following screenshot shows the details of this dynamic consumer on broker-2’s foo.bar queue.



    The following screenshot shows that the 100 messages which were dynamically moved from broker-2’s foo.bar queue to broker-1’s foo.bar queue have been successfully consumed by the consumer which we created in step #2


    This concludes part 2 of this series where we saw how duplex network connectors work.

    As always your comments are very welcome.

    Stay tuned for part 3 where we will go over load balancing consumers on local/remote brokers…

Ashwini Kuntamukkala

Ashwini is an open source, cloud and mobile development enthusiast. He has over 10 years of experience in leading and implementing several enterprise grade solutions in pharmacy, health care and travel industries. He is currently working as a Software Architect at SciSpike, Inc where they help their clients adopt best enterprise software development/governance practices through consulting, training and software development services. When not working and having fun with his family, he finds time to blog key ideas that he discovers when solving challenging problems.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button