ActiveMQ - Network of Brokers Explained (Part Three)
Join the DZone community and get the full member experience.
Join For FreeIntroduction
Ashwinis-MacBook-Pro:example akuntamukkala$ pwd /Users/akuntamukkala/apache-activemq-5.8.0/example Ashwinis-MacBook-Pro:example akuntamukkala$ ant consumer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar -DparallelThreads=3 -Dmax=20
Ashwinis-MacBook-Pro:example akuntamukkala$ ant producer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar -Dmax=60
[java] [Thread-3] Received: 'Message: 1 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-2] Received: 'Message: 0 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-1] Received: 'Message: 2 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-3] Received: 'Message: 4 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-2] Received: 'Message: 3 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-1] Received: 'Message: 5 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-3] Received: 'Message: 7 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-2] Received: 'Message: 6 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-1] Received: 'Message: 8 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000) [java] [Thread-3] Received: 'Message: 10 sent at: Tue Mar 04 13:46:53 IST 2014 ...' (length 1000)
Local Vs Remote Consumers
Let's see this in action
- Edit Broker-1's configuration /Users/akuntamukkala/apache-activemq-5.8.0/bridge-demo/broker-1/conf/activemq.xml and open a network connector to Broker-2 and restart Broker-1 and Broker-2
<networkConnectors> <networkConnector name="T:broker1->broker2" uri="static:(tcp://localhost:61626)" duplex="false" decreaseNetworkConsumerPriority="false" networkTTL="2" dynamicOnly="true"> <excludedDestinations> <queue physicalName=">" /> </excludedDestinations> </networkConnector> <networkConnector name="Q:broker1->broker2" uri="static:(tcp://localhost:61626)" duplex="false" decreaseNetworkConsumerPriority="false" networkTTL="2" dynamicOnly="true"> <excludedDestinations> <topic physicalName=">" /> </excludedDestinations> </networkConnector> </networkConnectors>
- Start local consumer, Consumer-1
Ashwinis-MacBook-Pro:example akuntamukkala$ ant consumer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar
- Start remote consumer, Consumer-2
Ashwinis-MacBook-Pro:example akuntamukkala$ ant consumer -Durl=tcp://localhost:61626 -Dtopic=false -Dsubject=foo.bar
- Start producer on Broker-1 to enqueue 100 messages
Ashwinis-MacBook-Pro:example akuntamukkala$ ant producer -Durl=tcp://localhost:61616 -Dtopic=false -Dsubject=foo.bar -Dmax=100
Please read the following link to gain further understanding of optimal routing by ActiveMQ.
This concludes part 3 of this series where we saw how to differentiate local and remote consumers to assist ActiveMQ determine most optimal path between message producers and consumers.
Published at DZone with permission of Ashwini Kuntamukkala, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments