Search This Blog

Sunday, 31 January 2021

JMS Server Concepts

 JMS

The Java Message Service (JMS) API is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. JMS is a part of the Java Platform, Enterprise Edition. It is a messaging standard that allows application components based on the Java 2 Platform, Enterprise Edition (J2EE) to create, send, receive, and read messages. It allows the communication between different components of a distributed application to be loosely coupled, reliable, and asynchronous. 

The following are JMS elements:

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.

JMS client

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

JMS producer/publisher

A JMS client that creates and sends messages.

JMS consumer/subscriber

A JMS client that receives messages.

JMS message

An object that contains the data being transferred between JMS clients.

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 have to be delivered in the order sent A JMS queue only guarantees that each message is processed only once.

JMS topic

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

The JMS API supports two models:

  • Point-to-point
  • Publish and subscribe

Point-to-point model :

In the point-to-point model, a sender posts messages to a particular queue and a receiver reads messages from the queue. Here, the sender knows the destination of the message and posts the message directly to the receiver's queue. This model is characterized by the following:

  • Only one consumer gets the message.
  • The producer does not have to be running at the time the consumer consumes the message, nor does the consumer need to be running at the time the message is sent.
  • Every message successfully processed is acknowledged by the consumer.



Publisher/Subscriber Model:

The publish/subscribe model supports publishing messages to a particular message topic. Subscribers may register interest in receiving messages on a particular message topic. In this model, neither the publisher nor the subscriber knows about each other. A good analogy for this is an anonymous bulletin board. The following are characteristics of this model:
  • Multiple consumers (or none) will receive the message.
  • There is a timing dependency between publishers and subscribers. The publisher has to create a message topic for clients to subscribe. The subscriber has to remain continuously active to receive messages, unless it has established a durable subscription. In that case, messages published while the subscriber is not connected will be redistributed whenever it reconnects.
Using Java, JMS provides a way of separating the application from the transport layer of providing data. The same Java classes can be used to communicate with different JMS providers by using the JNDI information for the desired provider. The classes first use a connection factory to connect to the queue or topic, and then use populate and send or publish the messages. On the receiving side, the clients then receive or subscribe to the messages.






Distributed Queue:

Many Producers can serialize messages to multiple receivers in a queue. 

Distributed Topic:

Publishing and subscribing to a topic decouples producers from consumers.



JMS Architecture: 

Step 1) Client will look up for a Connection Factory. 
Step 2) WebLogic will identify the connection factory from JNDI tree and return the connection factory to the client. Client creates a connection and a session is established.
Step 3) Client will look up for a destination from WebLogic using JNDI.
Step 4) WebLogic will return a destination. 
Step 5) Message will be placed at the destination Queue or Topic once the destination has been identified.









No comments: