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.
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>
<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:
- Q:broker1->broker2 network connector is duplex.
- 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:
- Duplex network connector from broker-2 to broker-1
- Two dynamic message producers from broker-1 to broker-2
- Please note that "Q:broker1->broker2" network connector shows as duplex as configured in activemq.xml
Let's see this in action
- Producer 100 messages into broker-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
2. Create a consumer on foo.bar on broker-1
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
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...