JMS Interview Questions and Answers

1 what is messaging?

Ans: Messaging is a method of communication between software components or applications.

2 what is JMS?

Ans: Java Message Service is a Java API that allows applications to create, send, receive, and read messages.

3 Is JMS a specification or a product?

Ans: JMS is a specification.

4 what are the features of JMS?

Ans: The following are the important features of JMS:
a. Asynchronous Processing.
b. Store and forwarding.
c. Guaranteed delivery.
d. Provides location transparency.
e. Service based Architecture.

5 what are two messaging models or messaging domains?

Ans: a. Point-to-Point Messaging domain.
b. Publish/Subscribe Messaging domain

6 Explain Point-to-Point Messaging model.?

Ans: A point-to-point (PTP) product or application is built around the concept of message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queue(s) established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages expire.

Point-to-Point Messaging has the following characteristics:
a. Each Message has only one consumer.
b. The receiver can fetch the message whether or not it was running when the client sent the message.
c. The receiver acknowledges the successful processing of a message.

7Explain Pub/Sub Messaging model.?

Ans: In a publish/subscribe (pub/sub) product or application; clients address messages? to a topic. Publishers and subscribers are generally anonymous and may dynamically publish or subscribe to the content hierarchy. The system takes care of distributing the messages arriving from a topic’s multiple publishers to its multiple subscribers. Topics retain messages only as long as it takes to distribute them to current subscribers.

Pub/sub messaging has the following characteristics:
a. Each message may have multiple consumers.
b. Publishers and subscribers have a timing dependency. A client that subscribes to a topic can consume only messages published after the client has created a subscription, and the subscriber must continue to be active in order for it to consume messages.

8 what are the two types of Message Consumption?

Ans: a. Synchronous Consumption: A subscriber or a receiver explicitly fetches the message from the destination by calling the receive method. The receive method can block until a message arrives or can time out if a message does not arrive within a specified time limit.

b. Asynchronous Consumption: A client can register a message listener with a consumer. A message listener is similar to an event listener. Whenever a message arrives at the destination, the JMS provider delivers the message by calling the listener’s on Message method, which acts on the contents of the message.

9 what is a connection factory?

Ans: A connection factory is the object a client uses to create a connection with a provider. A connection factory encapsulates a set of connection configuration arameters that has been defined by an administrator. Each connection factory is an instance of either the QueueConnectionFactory or the TopicConnectionFactory interface.

10 what is a destination?

Ans: A destination is the object a client uses to specify the target of messages it produces and the source of messages it consumes. In the PTP messaging domain, destinations are called queues and in the pub/sub messaging domain, destinations are called topics.

11 what is a message listener?

Ans: A message listener is an object that acts as an asynchronous event handler for messages. This object implements the Message Listener interface, which contains one method, on Message. In the on Message method, you define the actions to be taken when a message arrives.

12 what is a message selector?

Ans: Message selector filters the messages received by the consumer based on criteria. Message selectors assign the work of filtering messages to the JMS provider rather than to the application. A message selector is a String that contains an expression. The syntax of the expression is based on a subset of the SQL92 conditional expression syntax. The message consumer then receives only messages whose headers and properties match the selector.

13 Can a message selector select messages on the basis of the content of the message body?

Ans: No. The message selection is only based on message header and message

14 what are the parts of a JMS message?

Ans: A JMS message has three parts:
a. header
b. Properties (optional)
c. body (optional)

15 what is a message header?

Ans: A JMS message header contains a number of predefined fields that contain values that both clients and providers use to identify and to route messages. Each header field has associated setter and getter methods, which are documented in the description of the Message interface.

16 what are message properties?

Ans: Message properties are additional user defined properties other than those that are defined in the header.

17 what is the root exception of JMS?

Ans: JMSException is the root class for exceptions thrown by JMS API methods.

18? Name few subclasses of JMS Exception?

Ans: a. Message Format Exception
b. Message EOF Exception
c. Invalid Client ID Exception
d. Invalid Destination Exception
e. Invalid Selector Exception

19 what is a Message?

Ans: A message is a package of business data that is sent from one application to another over the network. The message should be self-describing in that it should contain all the necessary context to allow the recipients to carry out their work independently.

20 How many types are there and what are they?

Ans: There are 5 types of Messages. They are:

a. Text Message : A java.lang.String object (for example, the contents of an Extensible Markup Language file).

b. Map Message: A set of name/value pairs, with names as String objects and values as primitive types in the Java programming language. The entries can be accessed sequentially by enumerator or randomly by name. The order of the entries is undefined.

c. Bytes Message: A stream of uninterrupted bytes. This message type is for literally encoding a body to match an existing message format.

d. Stream Message: A stream of primitive values in the Java programming language, filled and read sequentially.

e. Object Message: A Serializable object in the Java programming language.