Welcome!

Java IoT Authors: Liz McMillan, Pat Romanski, Yeshim Deniz, Elizabeth White, Kong Yang

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,
simulators
and
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

Hi!

You can find the code here!

cheers.

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

Aleksandr,

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

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

Marco,

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

Hi,

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
www.sys-con.com/java/sourcec.cfm
link mentioned in this article.

Please advise.

@ThingsExpo Stories
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
In this presentation, Striim CTO and founder Steve Wilkes will discuss practical strategies for counteracting fraud and cyberattacks by leveraging real-time streaming analytics. In his session at @ThingsExpo, Steve Wilkes, Founder and Chief Technology Officer at Striim, will provide a detailed look into leveraging streaming data management to correlate events in real time, and identify potential breaches across IoT and non-IoT systems throughout the enterprise. Strategies for processing massive ...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA