jms interview questions and answers.Contains frequently asked interview questions on jms for freshers and experienced.
1)   What is JMS?
JMS stands for 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 asynchronously.
2)   What are the advantages of JMS?
JMS is asynchronous in nature. Thus not all the pieces need to be up all the time for the application to function as a whole. Even if the receiver is down the MOM will store the messages on it's behalf and will send them once it comes back up. Thus at least a part of application can still function as there is no blocking.
3)   What do you mean by Synchronous and Asynchronous type of messaging?
Synchronous: In this type of messaging, client waits for the server to respond to a message immediately. 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.
4)   How many types of messaging model do JMS provide for and what are they?
There are two types of messaging models that JMS provides :
1. Point to point queuing
2. public and subscribe
5)   What is the difference between topic and queue in JMS?
1. Queue technique is used for one to one messaging, and it supports point to point messaging. In this technique once a message is consumed by any one of the consumer, the message is destroyed from the queue.
2.Topic is typically used for one to many messaging and it supports public subscribe model of messaging. A single message can be consumed by multiple consumers.
6)   What is the role of the JMS provider?
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.
7)   What are the components of JMS?
8)   Give an example of using point to point model in JMS?
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.
9)   What is the important part of JMS applications?
Connection factory and destination
10)   What is JMS provider?
An implementation of the JMS interface for a Message Oriented Middleware (MOM). Providers are implemented as either a Java JMS implementation or an adapter to a non-Java MOM.
11)   What is JMS client?
An application or process that produces and/or receives messages.
12)   What is JMS producer?
A JMS client that creates and sends messages.
13)   What is JMS consumer?
A JMS client that receives messages.
14)   Mention the difference between durable and non-durable subscription in JMS?
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.
15)   Mention different types of messages available in JMS API?
The different types of messages available in JMS API are Message, TextMessage, BytesMessage, ObjectMessage and MapMessage.
16)   What is the difference between Byte Message and Stream Message in JMS?
Bytes Message stores data in bytes. Thus the message is one contiguous stream of bytes. While the Stream Message maintains a boundary between the different data types stored because it also stores the type information along with the value of the primitive being stored. Bytes Message allows data to be read using any type. Thus even if your payload contains a long value, you can invoke a method to read a short and it will return you something. It will not give you a semantically correct data but the call will succeed in reading the first two bytes of data. This is strictly prohibited in the Stream Message. It maintains the type information of the data being stored and enforces strict conversion rules on the data being read.
17)   What is the use of TextMessage in JMS?
TextMessage contains instance of java.lang.String as it's payload. Thus it is very useful for exchanging textual data. It can also be used for exchanging complex character data such as an XML document.
18)   What is the use of ObjectMessage in JMS?
ObjectMessage contains a Serializable java object as it's payload. Thus it allows exchange of Java objects between applications. This in itself mandates that both the applications be Java applications. The consumer of the message must typecast the object received to it's appropriate type. Thus the consumer should before hand know the actual type of the object sent by the sender. Wrong type casting would result in ClassCastException. Moreover the class definition of the object set in the payload should be available on both the machine, the sender as well as the consumer. If the class definition is not available in the consumer machine, an attempt to type cast would result in ClassNotFoundException. Some of the MOMs might support dynamic loading of the desired class over the network, but the JMS specification does not mandate this behavior and would be a value added service if provided by your vendor. And relying on any such vendor specific functionality would hamper the portability of your application. Most of the time the class need to be put in the classpath of both, the sender and the consumer, manually by the developer.
19)   Can we send e-mail messages using JMS?
JMS has no inherent support for email operations.
20)   What is the difference between JMS and RPC (Remote Procedure Call)?
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.
21)   What is MOM in reference to JMS?
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.e.g. ActiveMQ
22)   How you can deliver a java message to a non-java client in JMS?
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.
23)   For sending messages through JMS, what encryption options are there?
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.
24)   What are Message delivery stages in JMS?
Toward the end of delivery, the message conceptually passes through the following stages: message with JMS provider and message in application processing. Message with JMS provider In this stage, the message stays with the JMS provider just before the provider delivers it to the application. Consider a catastrophic situation where the JMS provider fails. What happens to the messages that the provider has not yet delivered to the client? Will the messages be lost? The messages' fate depends not upon the transaction options outlined earlier, but rather upon the delivery mode. There are two delivery modes: nonpersistent and persistent. Messages with nonpersistent delivery modes are potentially lost if the JMS provider fails. Messages with persistent delivery modes are logged and stored to a stable storage. The JMS provider saves these messages to a stable storage, such as a database or a file system, and eventually delivers them to the application for processing.
25)   What is Client acknowledgement in JMS?
To implement client acknowledgement mode, when you create the receiver's session, specify false as createSession()'s first argument and Session.CLIENT_ACKNOWLEDGE as its second argument. Specifying false creates a nontransacted session. In client mode, invoking the Message class's acknowledge() method explicitly acknowledges the message. In fact, using the acknowledge() method makes sense when only using the client mode.
Is this page helpful to you? Please give us your feedback below. We would love to hear your thoughts on these articles, it will help us improve further our learning process.
Contact us: email@example.com