JMS (i)--JMS basic concepts

Source: Internet
Author: User
Tags message queue

Summary: The Java Message Service (JMS) API is a messaging standard, allows application components based on the Java platfor M Enterprise Edition (Java EE) to create, send, receive, and read messages. IT enables distributed communication is loosely coupled, reliable, and asynchronous.

The JMS (JAVA message Service,java message Service) API is a standard or specification for a messaging service that allows application components to create, send, receive, and read messages based on the Java EE platform. It makes the distributed communication less coupled, the message service more reliable and asynchronous.

This blog post we mainly introduce a key specification in Java EE JMS, because this specification in the enterprise application is very broad, but also more important, we mainly introduce the basic concept of JMS and its mode, the consumption of messages and JMS programming steps. 

1. Basic Concepts

JMS is a Java messaging service that allows asynchronous message transmission between JMS clients through the JMS service.
2. Message Model

0point-to-point (PEER)
0publish/subscribe (Pub/sub)

Point-to-point and publish subscription models

3.1-Peer mode diagram

3.2 Related concepts

Message Queuing (queue) sender (sender) Recipient (receiver) is involved in each message being sent to a specific queue where the recipient obtains the message from the queue. The queue retains messages until they are consumed or timed out.

  3.3-Peer features 

each message has only one consumer (Consumer) (that is, once consumed, the message is no longer in the message queue) there is no dependency between the sender and the receiver in time, that is, when the sender sends the message, regardless of whether the receiver is running, It does not affect the message being sent to the queue receiver after successfully receiving the message to be successful in answering the queue if you wish to send every message should be successfully processed, then you need to peer-to mode.

4.1 pub/sub mode diagram

4.2 The conceptual 

theme (Topic) publisher (publisher) Subscriber (Subscriber) client that is involved in the message is sent to the topic. Multiple publishers send messages to topic, which the system passes to multiple subscribers. 4.3 pub/sub features Each message can have a time dependency between multiple consumer publishers and subscribers. Subscribers to a topic (TOPIC) must create a subscriber before they can consume the publisher's message, and the Subscriber must remain in the running state in order to consume the message. To mitigate such strict time dependencies, JMS allows subscribers to create a durable subscription. This way, even if the Subscriber is not activated (running), it can receive the message from the publisher. If you want to send a message that can be processed without any processing, or handled by a single message, or can be processed by multiple consumers, then you can use the Pub/sub model 

5. Message consumption

In JMS, the generation of messages and the message is asynchronous. For consumption, JMS messages can consume messages in two ways.
0 synchronization
A subscriber or receiver calls the Receive method to receive a message, and the receive method blocks until it is able to receive the message (or before it times out)
0 Async
Subscribers or receivers can register as a message listener. When the message arrives, the system automatically calls the listener's OnMessage method.
6.JMS programming Model

6.1 ConnectionFactory

The factory that created the connection object has two queueconnectionfactory and topicconnectionfactory for two different JMS message models. You can find the ConnectionFactory object through Jndi.
6.2 Destination

Destination means that the message producer's message is sent to the target or to the source of the message consumer. For a message producer, its destination is a queue or a topic (Topic), and for the message consumer, its destination is also a queue or topic (that is, the source of the message).

So, destination is actually two types of objects: Queue, topic can find destination through Jndi.
6.3 Connection

Connection represents the link established between the client and the JMS system (the wrapper to the TCP/IP socket). Connection can produce one or more sessions. Like ConnectionFactory, there are two types of connection: Queueconnection and Topicconnection.
6.4 Session

The session is the interface where we manipulate the message. You can create producers, consumers, messages, etc. through the session. The session provides the functionality of the transaction. These send/Receive actions can be placed in a transaction when we need to send/receive multiple messages using the session. Similarly, queuesession and topicsession are also divided.
6.5 Producers of messages

The message producer is created by the session and is used to send messages to destination. Similarly, there are two types of message producers: Queuesender and Topicpublisher. You can call the message producer's method (send or Publish method) to send the message.
6.6 Message Consumers

The message consumer is created by the session to receive messages sent to destination. Two types: QueueReceiver and TopicSubscriber. Can be created by Createreceiver (Queue) or Createsubscriber (Topic) of the session, respectively. Of course, you can also create a persistent subscriber by the Creatdurablesubscriber method of the session.
6.7 MessageListener

Message listeners. If a message listener is registered, the listener's OnMessage method is automatically invoked once the message arrives. An MDB (Message-driven Bean) in an EJB is a messagelistener.
7. Benefits of the Enterprise messaging system

Let's take a look at the diagram below, application A sends a message to the server, and then application B receives a send from the server, and through this diagram we analyze the benefits of JMS:

Provide message flexibility loosely coupled asynchrony for the basic concepts of JMS we've covered so much, and the next post introduces a JMS implementation.

Go from:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.