Top 40 Java Message Service (JMS) Interview Questions You Must Prepare 21.Apr.2024

JMS specification defines a traction mechanisms allowing clients to send and receive groups of logically bounded messages as a single unit of information. A Session may be marked as tracted. It me that all messages sent in a session are considered as parts of a traction. A set of messages can be committed (commit() method) or rolled back (rollback() method). If a provider supports distributed tractions, it's recommended to use XAResource API. 


Example for point to point model, would be a print out. When you select a print-out option, your system sends the message to the server, and once the print-out is taken out, again this server will send the message back to you. Point to point model is used, when the information is specific to a single client.

With publish/subscribe message passing the sending application/client establishes a named topic in the JMS broker/server and publishes messages to this queue. The receiving clients register (specifically, subscribe) via the broker to messages by topic; every subscriber to a topic receives each message published to that topic. There is a one-to-many relationship between the publishing client and the subscribing clients. 

Messaging is a method of communication between software components or applications. A messaging system is a peer-to-peer facility: A messaging client can send messages to, and receive messages from, any other client. Each client connects to a messaging agent that provides facilities for creating, sending, receiving, and reading messages.
Messaging enables distributed communication that is loosely coupled. A component sends a message to a destination, and the recipient can retrieve the message from the destination. However, the sender and the receiver do not have to be available at the same time in order to communicate. In fact, the sender does not need to know anything about the receiver; nor does the receiver need to know anything about the sender. The sender and the receiver need to know only what message format and what destination to use. In this respect, messaging differs from tightly coupled technologies, such as Remote Method Invocation (RMI), which require an application to know a remote application's methods.
Messaging also differs from electronic mail (e-mail), which is a method of communication between people or between software applications and people. Messaging is used for communication between software applications or software components.
Messaging is a mechanism by which data can be passed from one application to another application. 

The core JMS-related objects that are required are –
•The connection object
•One or more sessions within a connection that provides a context for message sending and receiving.
•A topic or queue object within a session representing the destination within the message broker.
•Appropriate sender or publisher or receiver within a session.

JMS administered object is a pre-configured JMS object that is created by an administrator for the use of JMS clients and placed in JNDI namespace.

JMS me Java Messaging Service.  It is the new standard for inter client communication. It allows the J2EE application component to create, send, read and receive the messages.

Publish/subscribe (pub/sub). This model allows a client (publisher) to send messages to a JMS topic. These messages are retrieved by other clients (subscribers) (it may happen so that a topic has no subscribers) asynchronously. Pub/sub model requires a broker distributing messages to different consumers. 

A publish-subscribe model is based on the message topic concept: Publishers send messages in a topic, and all subscribers of the given topic receive these messages. 

JMS client is a language program that sends or receives messages.

In RPC the method invoker waits for the method to finish execution and return the control back to the invoker. Thus it is completely synchronous in nature. While in JMS the message sender just sends the message to the destination and continues it's own processing. The sender does not wait for the receiver to respond. This is asynchronous behavior. 

@Use JNDI to locate administrative objects.
@Locate a single ConnectionFactory object.
@Locate one or more Destination objects.
@Use the ConnectionFactory to create a JMS Connection.
@Use the Connection to create one or more Session(s).
@Use a Session and the Destinations to create the MessageProducers and MessageConsumers needed.
@Perform your communication. 

The Java Message Service is a Java API that allows applications to create, send, receive, and read messages. Designed by Sun and several partner companies, the JMS API defines a common set of interfaces and associated semantics that allow programs written in the Java programming language to communicate with other messaging implementations.
The JMS API minimizes the set of concepts a programmer must learn to use messaging products but provides enough features to support sophisticated messaging applications. It also strives to maximize the portability of JMS applications across JMS providers in the same messaging domain.
The JMS API enables communication that is not only loosely coupled but also
Asynchronous. A JMS provider can deliver messages to a client as they arrive; a client does not have to request messages in order to receive them.
Reliable. The JMS API can ensure that a message is delivered once and only once. Lower levels of reliability are available for applications that can afford to miss messages or to receive duplicate messages.
The JMS Specification was first published in August 199@The latest version of the JMS Specification is Version 1.1, which was released in April 20@You can download a copy of the Specification from the JMS Web site,

•Message Producer
•Message Consumer
•Connection factory and destination

Synchronous: In this type of messaging, client waits for the server to respond to a message. Ex: Telephone call, two way radio communication.
Asynchronous: In this type of messaging, client does not wait for a message from the server, but automatically an event is created to trigger a message from a server. Ex: email, text messaging, blog posting.

Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server. So even if the client is down , the messaging will complete successfully. 


•JMS provider
•JMS client
•Administered objects
•Native clients

Durable subscription gives a subscriber the freedom of receiving all messages from a topic, while a non-durable subscription does not make any guarantees about messages sent by others when a client get disconnected by others.

A JMS message contains three parts. a header, an optional properties and an optional body. 

The different types of messages available in JMS API are Message, TextMessage, BytesMessage, ObjectMessage and MapMessage.

The JMS provider handles data conversion, security of the messages and the client triggering.  It specifies the level of encryption, security level of the message and the best-data type for the non-JMS client.

The application client like enterprise JavaBe components and web components can send or receive JMS message synchronously. In addition, the application clients can also receive message asynchronously.   With the help of message-driven be, JMS provider can optionally implement the processing of messages. Message-driven be are a type of enterprise bean that enables the asynchronous consumption of messages.
The operation of sending and receiving message is carried out in distributed operation, which allows JMS operations and database accesses within a single traction.

The MOM ( Message Oriented Middleware) is a software that works as an intermediate between two communicating components.  It is placed between the client and server, MOM provides the facility of passing message by using the technique queuing. Until the client does not request to read the message, the messages will be stored in queue.  By using this technique, the software component can work independently of time.

A point-to-point model is based on the concept of a message queue: Senders send messages into the queue, and the receiver reads messages from this queue. In the point-to-point model, several receivers can exist, attached to the same queue. However, (Message Oriented Middleware)MOM will deliver the message only to one of them. To which depends on the MOM implementation. 

JMS provides both type of messaging,

  • synchronous
  • Asynchronous

A JMS session is a single-threaded context for sending and receiving JMS messages.  A JMS session could be a locally tracted, non-tracted or distributed tracted.

JMS is the ideal high-performance messaging platform for intrabusiness messaging, with full programmatic control over quality of service and delivery options.
JavaMail provides lowest common denominator, slow, but human-readable messaging using infrastructure already available on virtually every computing platform.

The encryption and decryption of the messages is handled by JMS provider and not JMS specifications. Sonic MQ by Progress Software is a leading JMS provider and they do encryption through encryption mechanisms called Quality of Protection.


The basic difference between JMS and RPC lies in the way they message. JMS uses asynchronous messaging type while, RPC creates synchronous messaging type. The method invoker in RPC, waits for the method to finish execution and return back the control to the invoker. In JMS the message sender just sends the message to the destination and continues its own processing.

There are two types of messaging models that JMS provides –

  • Point to point queuing
  • Second one is public and subscribe

The main parts of JMS applications are:

  • ConnectionFactory and Destination
  • Connection
  • Session
  • MessageProducer
  • MessageConsumer
  • Message 

•With the help of Application server, the server session is created and it stores them in a pool
•To put messages in JMS session, connection consumer, uses the Server session
•Server session is the one that creates the JMS session
•Application written by Application programmers creates the message listener.

Byte message is a stream of uninterrupted bytes. It contains an array of primitive bytes in its payload.  For the trfer of data between two applications in their native format, byte message is used, which may be not possible with other message types.

One or more JMS clients that exchange messages. 

Synchronous messaging involves a client that waits for the server to respond to a message. So if one end is down the entire communication will fail. 

JMS has no inherent support for email operations.

First of all, after receiving the message from Topic or Queue, the message has to be converted into a non-java client according to their specification. The message once converted to non-java client, it can be delivered.

JMS provides for two messaging models, publish-and-subscribe and point-to-point queuing. 

The types of messages that are supported by JMS are
•Stream Messages
•Text Messages
•Map Messages
•Bytes Messages
•Object Messages

P2P model is highly reliable and it is used in a one-to-one situation, while subscribe model is used in one-to-many situation. It is very fast but less reliable.