Basic concepts of JMS (i)--JMS

Source: Internet
Author: User

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

    ○ Point-to-Point(P2P)○ Publish/Subscribe(Pub/Sub)

    Point-to-point and publish subscription models

  3. Peer to

    1. Peer mode diagram
    2. concepts involved
      1. Message Queuing (queue)
      2. Sender (Sender)
      3. Receiver (receiver)
      4. Each message is sent to a specific queue, and the recipient obtains the message from the queue. The queue retains messages until they are consumed or timed out.
    3. Features of the peer

      1. each message has only one consumer (Consumer) (that is, once consumed, the message is no longer in the message queue)
      2. between sender and receiver There is no dependency, that is, when the sender sends a message, regardless of whether the recipient is running, it does not affect the message being sent to the queue
      3. receiver to answer the queue successfully after successfully receiving the message

      If you want to send every message should be processed successfully, then you need to peer mode.

  4. Pub/sub

    1. Pub/sub mode diagram
    2. The concepts involved
      1. Theme (Topic)
      2. Publisher (publisher)
      3. Subscribers (subscriber)
        The client sends the message to the topic. Multiple publishers send messages to topic, which the system passes to multiple subscribers.
    3. Features of Pub/sub

      1. Each message can have multiple consumers
      2. There is a time dependency between the Publisher and the Subscriber. 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.
      3. 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 being processed, or handled by a single message, or can be processed by multiple consumers, then you can use the PUB/SUB model

  5. Consumption of messages
    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

    (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.

    (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.

    (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.

    (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.

    (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) 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.

    (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 this, 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:

    1. Provides message flexibility
    2. Loosely coupled
    3. of Asynchrony

So much for the basic concept of JMS, the next post introduces a JMS implementation.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Basic concepts of JMS (i)--JMS

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: info-contact@alibabacloud.com 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.