Welcome!

Java IoT Authors: Yeshim Deniz, Zakia Bouachraoui, Liz McMillan, Elizabeth White, William Schmarzo

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)

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.


IoT & Smart Cities Stories
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
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...
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
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...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
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...