About 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.

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

broker-2-100-msg-enqueue

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.

 <networkConnectors>
         <networkConnector 
            name="T:broker1->broker2" 
            uri="static:(tcp://localhost:61626)" 
            duplex="false" 
            decreaseNetworkConsumerPriority="true" 
            networkTTL="2" 
            dynamicOnly="true">
            <excludedDestinations>
                  <queue physicalName=">" />
            </excludedDestinations>
         </networkConnector>
         <networkConnector 
            name="Q:broker1->broker2" 
            uri="static:(tcp://localhost:61626)" 
            duplex="true" 
            decreaseNetworkConsumerPriority="true" 
            networkTTL="2" 
            dynamicOnly="true">
            <excludedDestinations>
                  <topic physicalName=">" />
            </excludedDestinations>
         </networkConnector>
     </networkConnectors>

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”.

broker-1-jconsole

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

broker-2-jconsole

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

    broker-2-duplex-noconsumers

  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).

    http://localhost:9161/admin/queues.jsp

    broker-2-duplex-msg-dequeued

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

    http://localhost:9161/admin/queueConsumers.jsp?JMSDestination=foo.bar

    broker-2-duplex-dynamicconsumer

    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

    broker-1-duplex-msg-consumed

    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…

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


− seven = 1



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close