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…

    Related Whitepaper:

    Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

    Get ready to program in a whole new way!

    Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

    Get it Now!  

Leave a Reply


1 × two =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books