Introduction
This article is written to give you basic understanding on how to make asynchronous message passing using JMS (Java Messaging Service). There are many tutorials available on how to create JMS Producer, JMS Queue Listener, JMS Consumer, etc.
But as per my knowledge none explain how to use message passing architecture in simple words. This article will give you better understanding on how to use JMS for messaging architecture.
Background
Consider a problem as follows:
“Create a web application sends a book id in a JMS Queue message. The business logic retrieves the message asynchronously and retrieves the book details from the database. It arranges all the data in an XML and returns back to the client. The client parses that XML and displays the data.”
The solution of this problem is explained into the following diagram:
To solve this problem, we need to create one JMS Message Producer (JSP page or servlet) that will produce BookID i.e. whose details need to be fetched from DataBase. This BookID will be stored into BookIDQueue and one Message-Driven Session Bean which will execute when a new message added into BookIDQueue because it is a kind of JMS Queue Listener that responds to onMessage event.
As stated into diagram the a remote EJB will be called from the Message Driven Bean onMessage that will fetch book details from DataBase using JPA and generate an XML for book details. This XML will be then added into BookDetailQueue by the same remote EJB.
Then one JMS Queue Consumer will be created in servlet that will read the messages of the queue and get them one by one and parses the message i.e. XML and get the book details.
This was the architectural design of the solution.
is final year M.Sc.I.T. student of J. P. Dawer Institute of Science and Information Technology, Surat, Gujarat, India and working at Riversand Technologies Inc. as software developer intern.