Reasons Why You Should Use JMS for Inter-Process Communication Within Computer Programs
Browse articles:
Auto Beauty Business Culture Dieting DIY Events Fashion Finance Food Freelancing Gardening Health Hobbies Home Internet Jobs Law Local Media Men's Health Mobile Nutrition Parenting Pets Pregnancy Products Psychology Real Estate Relationships Science Seniors Sports Technology Travel Wellness Women's Health
Browse companies:
Automotive Crafts, Hobbies & Gifts Department Stores Electronics & Wearables Fashion Food & Drink Health & Beauty Home & Garden Online Services & Software Sports & Outdoors Subscription Boxes Toys, Kids & Baby Travel & Events

Reasons Why You Should Use JMS for Inter-Process Communication Within Computer Programs

Programmers who create computer programs that have subsystems communicating with each other should consider using Java Message System (JMS) for inter-process communication rather than Remote Procedural Calls. Java Message System is easy to implement and time-saving. There are many more advantages that make JMS the preferred method for inter-process communication.

Nowadays, computer programs are made that require inter-process communication. Java Message Service, abbreviated as JMS, is the widely used method for communication between subsystems of a computer program without the involvement of a programmer. It overcomes various disadvantages of its predecessor: Remote Procedural Call (RPC).

Need for JMS

Normally, inter-process communication is achieved using Remote Procedural Calls (RPCs). However, this mode of communication is synchronous. Hence, the sender and receiver should be connected and synchronized in time for the communication to take place. However, this is undesirable as the receiver has to wait till the sender sends the message. This will cause the receiver to be idle till it receives the message. This form of relation between the sender and receiver is known as tight-coupling.

Due to the above disadvantages of RPC, a Message Oriented Middleware called Java Message Service (JMS) was invented. JMS uses asynchronous mode of communication, i.e., the sender sends the message whenever it wants and the receiver receives it at its own convenience. This lets the receiver do execution of other jobs and receive the message once it becomes free. This form of relationship between sender and receiver is known as loose-coupling.

Types of JMS

There are two types of JMS: Point to Point and Publish/Subscribe.

  1. Point to Point: In Point to Point model, there is one sender and one receiver. The sender sends to the sender queue from where it is transferred to the receiver queue. Whenever the receiver becomes available, it will read the message from the receiver queue.
  2. Publish/Subscribe: In this model, there are many senders and many receivers. There is a central system that arranges messages by categories. The sender sends the message to the central system. The message gets stored under the specified category. The message can be read by all receivers who have subscribed to that category and are available. Receivers are of two types: Durable Receivers – Receivers who have subscribed to specific senders (in addition to categories) and hence will receive the message when they become available, if not available at the instant message arrives, and Non-Durable Receivers – Receivers who have subscribed to a specific category only, and hence will lose the messages that come to that specific category, if they are not available.

Components of a JMS message

  1. Header: It consists of the address of the receiver queue or the category to which the message should be sent.
  2. Properties: Information such as when the message was sent, whether the message was received properly are stored in this part of the message.
  3. Body: This contains the actual message to be sent.

Steps to create a Message Producer (Sender)

  1. Create a Context. A Context is used as a gateway to access Java Naming and Directory Interface (JNDI). Java Naming and Directory Interface is a facility that lets an address be identified by a name. This makes it easy to access queues, receivers, etc. in the system.
  2. From the Context, create a Connection Factory.
  3. From the Connection Factory, create a Connection.
  4. From the Connection, create a Session.
  5. Lookup a queue from JNDI or create one.
  6. Create a Message Producer.
  7. Send the message using the Producer.

Steps to create a Message Consumer (Receiver)

  1. Follow steps 1-5 as above.
  2. Create a Message Consumer.
  3. Start the Connection.
  4. Receive the message using the Consumer.

Advantages of using JMS

  • It is asynchronous. Hence, it saves time.
  • It is heterogeneous. Processes in two different platforms, E.g. Windows and Linux, can communicate between each other using JMS. Hence, there is no constraint to develop the complete program in one platform. Subsystems of a program can be developed in different platforms and integrated together.
  • It is a Middleware application. Hence, to alter the Messaging system, neither the lower level (database – Place where all the data regarding an application is stored) nor the higher level (Components that interact with the user – web pages, forms, etc.) components need to be changed.
  • It offers more flexibility to software program developers. Since JMS is easy, time-saving and advantageous to use, it is preferred over RPC for inter-process communication.

Additional resources:

Need an answer?
Get insightful answers from community-recommended
in Computer Programming & Languages on Knoji.
Would you recommend this author as an expert in Computer Programming & Languages?
You have 0 recommendations remaining to grant today.
Comments (2)

Very well detailed and presented facts on this valuable topic.thank you.

1. you can easily have asynchronous RPC (GWT is an example) 2. saying that synchronous communication is undesirable is wrong. There are situations where the opposite is true. 3. loose and tight coupling have absolutely nothing to do with communication being sync/async.