Showing posts with label activemq jms sequencing. Show all posts
Showing posts with label activemq jms sequencing. Show all posts

Tuesday, August 7, 2012

ActiveMQ Mirror Queue: Working Example.


If you reached here, you might have already checked few very confusing paragraphs about Mirror queues in ActiveMQ.
Mirror Queues are disabled by default. To enable them, you have to following settings in activemq.xml
<destinationInterceptors>
<mirroredQueue copyMessage = "true" postfix="" prefix="MIRROR."/>
                <virtualDestinationInterceptor>
                                <virtualDestinations>
                                                <virtualTopic name="MIRROR.TEST.>"  prefix="MIR.>." selectorAware="false"/>
                                </virtualDestinations>
                </virtualDestinationInterceptor>
</destinationInterceptors>
               
Out of above: “<mirroredQueue copyMessage = "true" postfix="" prefix="MIRROR."/>” is actually responsible for enabling Mirror Queues.

How ActiveMQ Handles Mirror Queues:

1.       When you enable Mirror Queues, with say prefix as “MIRROR.”, for every queue in the broker one Topic will be created with MIRROR. Prefix.
2.       Now to receive a message from this Topic, Virtual Destinations can be used. More about Virtual Destination can be found here.

Working Example:

                Let’s consider above configuration for prefix for Mirror queues and Virtual Destinations.
1.       Create a queue: TEST.QUEUE
2.       With above settings, Mirror Topic is automatically created as : MIRROR.TEST.QUEUE
3.       Create Virtual Topic Consumer : MIR.COPY.MIRROR.TEST.QUEUE
a.       MIR – Defined Virtual Topic Interceptor
b.      COPY – Name of the Consumer
c.       MIRROR.TEST.QUEUE – is a Topic Name
4.       Send a test message to TEST.QUEUE, same message will appear in MIR.COPY.MIRROR.TEST.QUEUE.

This is complete setting of Mirror Queues.

Problems:

1.       Mirror Topics will be created for Every Queue in the broker
2.       As broker has to track each message from the queue and copy it to topic, further to virtual destination, broker may face performance problem depending on load.

Friday, June 29, 2012

ActiveMQ Message Sequencing : Analysis Part I

Message Sequencing POC:
In most of the corporate production environments, messages are not sent and received from the same broker. Message might end up from multiple hops and clusters within infrastructure before it actually hits the business consumer. I did a small analysis with ActiveMQ out of the box configuration to use sequencing. Below are the results.
Test Case 1:
Messages are sent to queue / Topic and received in same broker (even from Virtual Destination queue). Single producer and exclusive consumer are used.
Result:
1.       Messages are always received in Sequence in normal running consumer
2.       Message maintains their sequence even if consumer thread restarts in between
3.       Message Priority is IGNORED and sequenced is maintained 
4.       Results matches the documentation provided here: http://activemq.apache.org/exclusive-consumer.html
Test Case 2:
Messages are going through multiple hops before get consumed from exclusive consumer.
Result:
1.       Message loses sequence
2.       Priority Set on the messages resets to default (‘4’) regardless of producing value.

Summary:
·         If producer and consumer maintained in same broker and consumers are made exclusive; message sequencing is guaranteed.
·         If message is making multiple hops before reaching to consumer, sequencing is NOT guaranteed even if Exclusive consumers are used.

 In Part II, we will use JMXGroupId concept for message sequencing and find the right results.