Over a million developers have joined DZone.

JMS Queue: When Size Does Matter

· Integration Zone

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and dPaaS could cost you down the road. Brought to you in partnership with Liaison Technologies.

[This article was written by Adrian Hsieh.]

Anypoint Platform is fast. The legacy systems that it often connects to? Not so much.

Therefore, in real world use cases, the requirements often call for limiting the message throughput to protect the endpoint systems from being overwhelmed by traffic. Architectural designs that support message throttling commonly incorporate some elements of message queues to stage and hold messages in-flight, so that the endpoints can process them at a steadier pace.

For architectures with throttling, it is often important to be able to count how many messages in the queues are still waiting to be consumed. For example, if certain threshold has been crossed, an alert may need to be sent to the operation center, or the inbound polling may have to be stopped completely until the queue size falls below threshold again, only then can intaking of messages resume.

Muley counting his new friends.

Muley’s counting his new friends.

The QueueBrowser interface can be used to count the number of messages in-flight on the queues. For working with a Mule flow, an option is to write a custom Mule component that uses the . Note that it is best to make the custom component a Spring bean to take advantages of using property placeholders, to make it easier to specify host address and port number.

        <spring:bean id="queue-counter" name="queue-counter" class="org.mule.api.jms.extension.CurrentQueueSize">
            <spring:property name="port1" value="${jms.port1}"/>
            <spring:property name="host1" value="${jms.host1}"/>
            <spring:property name="port2" value="${jms.port2}"/>
            <spring:property name="host2" value="${jms.host2}"/>
        </spring:bean>

With this approach, counting in the flow is as simple as this:

        <enricher   doc:name="Message Enricher">
            <component doc:name="queue-counter">
                <spring-object bean="queue-counter"/>
            </component>
            <enrich source="#[payload['${r2s.dlq}']]" target="#[flowVars['dlq-size']]"/>
            <enrich source="#[payload['${r2s.queue}']]" target="#[flowVars['queue-size']]"/>
        </enricher>

The sample code for a Mule Java component, written for ActiveMQ, is shown below. Note that failover is fully supported. In the example, performance is not a paramount concern, therefore, all the queues are being counted in one call. The code can be easily modified though, so the queue name is also passed in as a property and counting will be done only for the specified queue.


Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison Technologies.

Topics:
java ,enterprise-integration ,tutorial ,jms ,integration ,mule ,activemq ,muleesb ,message queue

Published at DZone with permission of Ross Mason, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}