Java IoT Authors: Liz McMillan, Zakia Bouachraoui, Yeshim Deniz, Elizabeth White, Pat Romanski

Related Topics: Java IoT

Java IoT: Article

Generic Request Response Broker for JMS

A robust and easy-to-use implementation of the Request-Response paradigm

This article describes the design and implementation of a generic request/response broker (RRB) for JMS. RRB augments JMS with a highly efficient implementation of the request-response paradigm.

It's extremely important for many asynchronous applications since JMS has somewhat weak built-in support for the request-response paradigm that might be inadequate for high-load enterprise applications. RRB solves the following common problems. It:

  • Provides a generic high-performance application and JMS provider-independent implementation of the request-response pattern.
  • Supports timeouts for non-blocking clients.
  • Allows efficient handling of a large number of requests/responses.
  • Lets one hide all the JMS details behind the façade interface.
  • Reduces performance degradation when a request travels through multiple façade proxies.
Possible Solutions and Their Performance Comparison
Request-response pattern is popular in enterprise applications: a client application sends a request message to a server app, which handles the request and sends the response back to the client. Here's what JMS offers for this pattern:
  • JMSMessageID and JMSCorrelationID headers can be used to link requests and responses.
  • JMSReplyTo header lets the recipient of a request know where to send the response.
  • TopicRequestor/QueueRequestor helpers allow sending a request and block until a response is received.
TopicRequestor/QueueRequestor is the only JMS built-in "request-response broker" and has three drawbacks:
  • It's a blocking call.
  • You're not allowed to specify a timeout in the only existing request() method, so your thread may be blocked forever if there's no response.
  • It creates and deletes a temporary response destination for every request, which has big performance implications as we'll see later.
Because of these drawbacks, the burden of implementing timeouts and retrieving response messages efficiently is left to the developers of the client applications and that's exactly what RRB is designed to solve (The source code for this article can be downloaded from www.sys-con.com/java/sourcec.cfm.)

Timeout for Non-blocking Clients
Standard JMS lets the client provide a timeout only for the blocking (synchronous) calls in the method MessageConsumer.receive(): a client is blocked until the message is received or the time specified has expired. Of course, a blocking call isn't a preferred way in JMS to get a message. It's better to use a MessageListener object registered with a particular destination that's called whenever a message is received. Unfortunately standard JMS makes no provision for using timeouts with asynchronous calls using listeners: MessageListener only has onMessage() callback methods and no onTimeout(). That means your listener will be called only when a message is posted to the destination you're listening on; it'll never be called if for some reason the message you expected never arrived. In many real-life apps and in almost every request-response scenario you can't wait for a message indefinitely (especially if it's a response). You need to bail out after some timeout.

Efficient Implementation of the Response Handling
In JMS there are three ways to get a response message:

1.  Create/delete a temporary destination per request

  • Pros:
    - Clean design, response destination isn't shared, no filtering required
    - Relatively easy to implement
  • Cons:
    - Inherently bad performance (temporary destinations are always created inside the MOM provider, which generally means two extra network calls: create and delete a temporary destination plus all the housekeeping and resources on the app server to maintain the temp destination).
2.  Use the same destination for multiple responses in combination with JMS selectors for filtering
  • Pros:
    - Relatively clean design, no filtering in the client once the selector is set up
  • Cons:
    - Questionable performance: some vendors don't recommend using selectors
    - Many possible pitfalls (for example, selectors on strings are much slower than on integers)
3.  Use the same destination for multiple responses without JMS selectors
  • Pros:
    - Can be fast depending on the implementation
  • Cons:
    - Filtering has to be done in the client's code
    - Many possible pitfalls that will result in lost or doubly handled messages (for example, when two or more apps use the same "unique" application_id properties for filtering)
    - High load on the client listeners (in case of a response topic) that are called every time a message is received and subsequently discarded by all but one listener
To fully understand the performance impact of the different retrieval options mentioned above I wrote a simple JMS server app (EchoClient.java) and three different JMS client apps for every option: EchoClientMultTempQs.java, EchoClientSelector.java, and EchoClient.java. These clients will show the performance metrics of each message retrieval approach. All the tests were run in the same environment: one physical Linux box using three separate JVMs, echo client, JMS provider, and an echo server.

Option 1. A new temp destination for every response:

java EchoClientMultTempQs echo_server.properties 1000
N of reqs/resps = 1000
Total time = 13765 millisecs
Average roundtrip time = 13.765 millisecs

Option 2. The same destination using jms selectors for filtering:

java EchoClientSelector echo_server.properties 1000
N of reqs/resps = 1000
Total time = 10705 millisecs
Average roundtrip time = 10.705 millisecs

More Stories By Lev Kochubeevsky

Lev Kochubeevsky is a chief architect at AOL in Dulles, Virginia.
His main areas of interest include high performance enterprise systems,
distributed software architectures, messaging, virtual machines,
debuggers. Lev holds a master degree in computer science.

Comments (5) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
fred 10/08/09 04:04:00 PM EDT


You can find the code here!


Lev Kochubeevsky 05/21/05 11:31:41 PM EDT


Please contact JDJ site admin to report a problem with the source code availability.

Lev Kochubeevsky 05/21/05 11:28:50 PM EDT


I used only standard JMS code ( v.1.02 ) in RRB so it will work with any JMS provider.

Marco 05/19/05 11:03:41 AM EDT


i would like to know what JMS provider use for trying the example.

Thank you

aleksandr 05/17/05 04:21:43 PM EDT

Can not load source code for this article using
link mentioned in this article.

Please advise.

IoT & Smart Cities Stories
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
DXWorldEXPO LLC, the producer of the world's most influential technology conferences and trade shows has announced the 22nd International CloudEXPO | DXWorldEXPO "Early Bird Registration" is now open. Register for Full Conference "Gold Pass" ▸ Here (Expo Hall ▸ Here)
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time t...