Prev Next

Spring / JMS

1. What is JMS (Java Messaging Service)? 2. How JMS (Java messaging service) is different from RPC (Remote Procedure call)? 3. What type of messaging is provided by JMS? 4. Explain Synchronous messaging in JMS. 5. Explain Asynchronous messaging in JMS. 6. What are the advantages of JMS? 7. Different types of Messaging models in JMS. 8. Difference between Point to Point and Publish/Subscribe models in JMS. 9. Difference between topic and queue in JMS. 10. Name some of the other major JMS products available in the market. 11. What are the components of JMS? 12. Explain the role of the JMS provider. 13. Give an example of the publish/subscribe model in JMS. 14. What are the important components of a JMS application? 15. What is JMS administered object? 16. What is JMS session? 17. Difference between durable and non-durable subscription in JMS. 18. Different types of messages available in JMS API. 19. Can JMS be used to send an email? 20. What is Message object in JMS? 21. What is the use of BytesMessage in JMS? 22. Describe the use of StreamMessage in JMS. 23. What is the use of TextMessage in JMS? 24. What is the use of ObjectMessage in JMS? 25. What is the use of MapMessage in JMS? 26. Wat is JMS client? 27. What is JMS producer and Consumer? 28. What is JMS queue? 29. What is JMS topic? 30. Describe Messaging. 31. Explain the difference between Java Mail and JMS Queue. 32. How does a typical JMS client perform the communication using JMS. 33. Define a JMS application. 34. What is the difference between Byte Message and Stream Message? 35. How does the Application server handle the JMS Connection? 36. Explain how JMS works with the J2EE? 37. Can I deliver a Java message to a non-java client? 38. Lets say I had received the JMS message from Queue/Topic and application went down with some issue. So is it possible to retrieve JMS message and continue the execution? if Yes, how is that done. 39. Explain the relationship between the Java Message Service, the Java Transaction API, and the Java Transaction Service.
Could not find what you were looking for? send us the question and we would be happy to answer your question.

What is JMS (Java Messaging Service)?

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.

How JMS (Java messaging service) is different from RPC (Remote Procedure call)?

JMS provides asynchronous messaging while RPC is synchronous.

In RPC the client who invokes the method need to wait for the method to complete the execution and return the control back to the invoker due to its synchronous nature. In JMS the message sender just sends the message to the destination and continues its own processing. The sender does not need to wait for the receiver to respond as JMS is asynchronous.

What type of messaging is provided by JMS?

JMS provides two type of messaging.

  • Synchronous
  • Asynchronous
Explain Synchronous messaging in JMS.

In synchronous messaging, client waits for the server to respond to a message before it continue its own processing.

Explain Asynchronous messaging in JMS.

In asynchronous messaging, client does not wait for a message from the server, instead it automatically creates an event to trigger when response received from server. For example, email and text messaging.

What are the advantages of JMS?

Asynchronous messaging.

Reliability. Ensures once and only once message delivery.

Loose coupling. JMS can be used in heterogeneous environments with decoupled systems that can communicate over system boundaries.

Different types of Messaging models in JMS.

There are 2 types of messaging models that JMS provides,

  • Point to Point,
  • and Publish and Subscribe method.

Difference between Point to Point and Publish/Subscribe models in JMS.

In point to point communication (one producer and one consumer), the producers and consumers of the message are defined. The producers push the messages in the queues and the receivers retrieve them. It is highly reliable.

In publish and subscribe method (one producer and one or more consumer), the producers publish the message and the subscribers who have subscribed to that topic receive them. In this way, a message may be received, or processed, by multiple consumers. It is unreliable however very fast.

Difference between topic and queue in JMS.

Queuing is used for one to one messaging and it supports point to point messaging model while topic is typically used for one to many messaging and it supports public subscribe model of messaging.

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

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.

What are the components of JMS?
  • JMS provider.
  • JMS client.
  • Messages.
  • Administered objects.
  • and Native clients.
Explain 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.

Give an example of the publish/subscribe model in JMS.

JMS can be used to broadcast shutdown messages to clients connected to the Weblogic server on module basis. If an application has many modules, each module behaves like a subscriber to a named topic on the server receive and process the message.

What are the important components of a JMS application?
  • Session.
  • Connection.
  • Message.
  • Message Producer and Consumer .
  • Connection factory and destination.

What is JMS administered object?

JMS administered object refers to the preconfigured JMS object created by an administrator for the use of JMS clients and placed in JNDI namespace.

What is JMS session?

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

Difference between durable and non-durable subscription in JMS.

Durable subscription enables the subscriber to receive 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.

Different types of messages available in JMS API.

The different types of messages available in JMS API are,

  • StreamMessage,
  • TextMessage,
  • BytesMessage,
  • ObjectMessage,
  • and MapMessage.
Can JMS be used to send an email?

JMS has no support for email operations.

What is Message object in JMS?

Message is a light weight message having only header and properties and no payload. If receivers are to be notified about an event, and no data needs to be exchanged then using Message can be very efficient.

What is the use of BytesMessage in JMS?

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.

Describe the use of StreamMessage in JMS.

StreamMessage carries a stream of Java primitive types as it's payload. Unlike ByteMessage, there are restrictions on the way the data is read to avoid erroneous output. StreamMessage prevents reading a long value as short, something that is allowed in case of BytesMessage. SreamMessage enforces a set of strict conversion rules which actually prevents reading of one primitive type as another.

What is the use of TextMessage in JMS?

TextMessage contains instance of java.lang.String as its 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.

What is the use of ObjectMessage in JMS?

An ObjectMessage object is used to send a message that contains a serializable object in the Java programming language ("Java object").

What is the use of MapMessage in JMS?

A MapMessage holds name-value pair as its payload thus it is similar to the java.util.Properties object of Java. The values can be Java primitives or its wrappers.

Wat is JMS client?

An application or process/component that produces and/or receives messages.

What is JMS producer and Consumer?

JMS producer is a JMS client that creates and sends messages.

JMS consumer is a JMS client that receives messages.

What is JMS queue?

A staging area that contains messages that have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages don't have to be delivered in the order sent. If the message driven bean pool contains more than one instance then messages can be processed concurrently and thus it is possible that a later message is processed sooner than an earlier one. A JMS queue guarantees only that each message is processed only once.

What is JMS topic?

A distribution mechanism for publishing messages that are delivered to multiple subscribers.

Describe Messaging.

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.

Messaging is different 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.

Explain the difference between Java Mail and JMS Queue.

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.

How does a typical JMS client perform the communication using JMS.
  • 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.
Define a JMS application.

A JMS application can have one or more JMS clients that exchange messages.

What is the difference between Byte Message and Stream Message?

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.

How does the Application server handle the JMS Connection?
  • 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.

Explain how JMS works with the J2EE?

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.

Can I deliver a Java message to a non-java client?

Yes. After the message is received from Topic or Queue, the message may be converted into a non-java client according to its specification and delivered.

Lets say I had received the JMS message from Queue/Topic and application went down with some issue. So is it possible to retrieve JMS message and continue the execution? if Yes, how is that done.

Hi there, thanks for your question. We have Ack (acknowledge) and Nak (not acknowledge) mechanism which may be utilized for this scenario.

When your application does receive a JMS message, process it and finally, it may acknowledge the queue so that it may not receive it again anymore. When the application goes down and it may not acknowledge so QUEUE will replay the message. Hope this helps.

Explain the relationship between the Java Message Service, the Java Transaction API, and the Java Transaction Service.

The below answer is taken from Oracle website as this is best fit.

The Java Transaction API (JTA) provides a client API for delimiting distributed transactions and an API for accessing a resource's ability to participate in a distributed transaction. A JMS client may use JTA to delimit distributed transactions. A JMS provider can optionally support distributed transactions via JTA.

The Java Transaction Service (JTS) can be used with the JMS API to form distributed transactions that combine message sends and receives with database updates and other JTS aware services. These services should be handled automatically when a JMS client is run from within an application server such as a J2EE server; however, it is also possible for JMS clients to program them explicitly.

«
»
Java Transactions (JTA)

Comments & Discussions