Introduction to JMS and ActiveMQ

1. Introduction to JMS

       JMS is the Java Message Service ( Java Message Service ) application program interface, which is a message-oriented middleware (MOM) API in the Java platform, which is used to send messages between two applications or in a distributed system for asynchronous communication . Java Message Service is a platform-independent API, and most MOM providers support JMS.

        J MS is a Java message service, and asynchronous message transmission can be performed between JMS clients through the JMS service.

        JMS is a vendor-independent API for accessing messaging system messages. It is similar to JDBC (JavaDatabase Connectivity): Here, JDBC is an API that can be used to access many different relational databases, while JMS provides the same vendor-independent access methods to access messaging services. Many vendors support JMS, including IBM's MQSeries, BEA's Weblogic JMS service, and Progress's SonicMQ, to name just a few. JMS enables you to send messages from one JMS client to another through a messaging service (sometimes called a message broker or router).

       A message is a type object in JMS that consists of two parts: a header and a message body . The header consists of routing information and metadata about the message. The message body carries the application's data or payload. According to the type of payload, the message can be divided into several types, which carry: simple text (TextMessage), serializable object (ObjectMessage), property collection (MapMessage), byte stream (BytesMessage), raw A stream of values ​​(StreamMessage), and a message without payload (Message) .

Second, the JMS architecture

JMS consists of the following elements.

J MS provider (such as ActiveMQ, which provides message services) : Connect to message-oriented middleware, an implementation of the JMS interface. The provider can be a JMS implementation for the Java platform, or a message-oriented middleware adapter for a non-Java platform.

JMS Client : A Java application or object that produces or consumes message-based.

    1. JMS producer: A JMS client that creates and sends messages.

    2. JMS consumers: JMS clients that receive messages.

JMS message : An object that includes data that can be passed between JMS clients

JMS Queue : An area that holds messages that are sent waiting to be read. Contrary to what the queue name implies, messages are not necessarily received in the same order as they are sent. Once a message is read, the message will be removed from the queue.

JMS Topics : A mechanism that supports sending messages to multiple subscribers.


3. ActiveMQ

Two message models of JMS message service: point-to-point model and publisher/subscriber model

1. Point-to-point model

       A producer publishes messages to a specific queue, and a consumer reads messages from that queue. Here, the producer knows the consumer's queue and sends messages directly to the consumer's queue.

2. Publisher/Subscriber Model

      Supports publishing messages to a specific message topic . 0 or more subscribers may be interested in receiving messages from a particular message topic. Under this model, publishers and subscribers are unaware of each other. This model is like an anonymous bulletin board .

4. Installation


The code part of the producer consumer to send and receive messages is also very simple, so I won't go into details.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774435&siteId=291194637