Top Interview Questions & Answers | Learn Now

JMS Interview Questions And Answers | Basic and Advanced Levels

Written by Mohammed | Mar 28, 2018 9:03:38 AM

Q1. What is JMS (Java Messaging Service)?

Ans: JMS (Java Messaging Service) is a messaging standard that allows J2EE application components to create, send, receive, and read messages. JMS defines an enterprise messaging Java API that makes it easy to write business applications that can exchange business data and events asynchronously and reliably in a vendor-agnostic manner.

Q2. What type messaging is provided by JMS?

Ans: synchronous and asynchronous.

Q3. What are the advantages of JMS?

Ans: 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.

Q4. What are the components of JMS?

Ans:

  • JMS provider.
  • JMS client.
  • Messages.
  • Administered objects.
  • and Native clients.

Q5. What are the important components of a JMS application?

Ans:

  • Session.
  • Connection.
  • Message.
  • Message Producer and Consumer .
  • Connection factory and destination.

Q6. How JMS is different from RPC?

Ans: 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.

Q7.What is the Role of the JMS Provider?

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

Q8. What are the core JMS-related objects required for each JMS-enabled application?

Ans: Each JMS-enabled client must establish the following:

  • A connection object provided by the JMS server (the message broker)
  • Within a connection, one or more sessions, which provide a context for message sending and receiving
  • Within a session, either a queue or topic object representing the destination (the message staging area) within the message broker
  • Within a session, the appropriate sender or publisher or receiver or subscriber object (depending on whether the client is a message producer or consumer and uses a point-to-point or publish/subscribe strategy, respectively). Within a session, a message object (to send or to receive)

Q9. Different types of Messaging models in JMS.

Ans: There are 2 types of messaging models that JMS provides:

  1. Point to Point,
  2. and Publish and Subscribe method.

Q10. Name some of the other major JMS products available in the market.

Ans: IBM's MQ Series is one of the most popular product used as Message Oriented Middleware. Some of the other products include SonicMQ, iBus etc.
All the J2EE compliant application servers come with its own implementation of JMS.

Q11. What is JMS session?

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

Q12. What is publish/subscribe messaging?

Ans: 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.

Q13. Why doesn’t the JMS API provide end-to-end synchronous message delivery and notification of delivery?

Ans: Some messaging systems provide synchronous delivery to destinations as a mechanism for implementing reliable applications. Some systems provide clients with various forms of delivery notification so that the clients can detect dropped or ignored messages. This is not the model defined by the JMS API. JMS API messaging provides guaranteed delivery via the once-and-only-once delivery semantics of PERSISTENT messages. In addition, message consumers can insure reliable processing of messages by using either CLIENT_ACKNOWLEDGE mode or transacted sessions. This achieves reliable delivery with minimum synchronization and is the enterprise messaging model most vendors and developers prefer. The JMS API does not define a schema of systems messages (such as delivery notifications). If an application requires acknowledgment of message receipt, it can define an application-level acknowledgment message.

Q14. What is the role of JMS in enterprise solution development?

Ans: JMS is typically used in the following scenarios

  1. Enterprise Application Integration: - Where a legacy application is integrated with a new application via messaging.
  2. B2B or Business to Business: - Businesses can interact with each other via messaging because JMS allows organizations to cooperate without tightly coupling their business systems.
  3. Geographically dispersed units: - JMS can ensure safe exchange of data amongst the geographically dispersed units of an organization.
  4. One to many applications: - The applications that need to push data in packet to huge number of clients in a one-to-many fashion are good candidates for the use JMS. Typical such applications are Auction Sites, Stock Quote Services etc.

Q15. What is the use of Message object?

Ans: Message is a light weight message having only header and properties and no payload. Thus if theIf the receivers are to be notified abt an event, and no data needs to be exchanged then using Message can be very efficient.

Q16. Different types of messages available in JMS API.

Ans: The different types of messages available in JMS API are:

  • StreamMessage,
  • TextMessage,
  • BytesMessage,
  • ObjectMessage,
  • and MapMessage.

Q17. Can JMS be used to send an email?

Ans: JMS has no support for email operations.

Q18. What is the use of BytesMessage in JMS?

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

Q19. How does the Application server handle the JMS Connection?

Ans:

  • App server creates the server session and stores them in a pool.
  • Connection consumer uses the server session to put messages in the session of the JMS.
  • Server session is the one that spawns the JMS session.
  • Applications written by Application programmers creates the message listener.

Q20. Explain how JMS works with the J2EE?

Ans:

  • The enterprise JavaBeans components and web components can send or receive JMS message asynchronously. In addition, the application clients can also receive message asynchronously. Using message-driven beans, JMS provider can optionally implement the processing of messages. Message-driven beans are a type of enterprise bean that enables the asynchronous consumption of messages.
  • The operation of sending and receiving message is performed as distributed operation, which allows JMS operations and database accesses within a single transaction.