JMS Notes (i)

Source: Internet
Author: User

1.JMS concept

The Java Message Service provides a way for Java programs to access the Enterprise messaging system, which is composed of JMS producers, JMS Provider, JMS consumers

1.1. Composition of a message

(1) header (head)

Each JMS message must have a message header. The header field contains values for routing and identifying messages. There are several ways to set the value of a message header:

A. Automatically set by the JMS provider during the generation or delivery of messages

B. Set by the producer client by the settings specified when creating the message producer

C. Set each message individually by the producer client

(2) Attribute (property)

A message can contain an optional header field called a property. They are made in the form of property names and property value pairs. You can extend a property to a message header, which can include information such as the process that created the data, when the data was created, and the structure of each piece of data. The JMS provider can also add properties that affect message processing, such as whether the message should be compressed or how to discard the message at the end of the message life cycle.

(3) Body (body)

Contains the content to be sent to the receiving application. Each message interface is specific to the type of content it supports. JMS provides their own message types for different types of content, but all messages derive from the message interface.

Streammessage a message that contains a stream of Java primitive values in a body. Its padding and reads are performed sequentially.

Mapmessage a message that contains a set of key-value pairs in a body. No entry order defined.

TextMessage a message that contains a Java string in the body (for example, an XML message).

ObjectMessage a message that contains a serialized Java object in the body.

Bytesmessage a message that contains a continuous stream of bytes in the body.

1.2. Message Delivery model

JMS supports two messaging models: Point-to-point (point-to-point, short-to-peer) and publish/subscribe (Publish/subscribe, abbreviated PUB/SUB)

Peer Features:

(1) Each message has only one consumer (Consumer) (that is, once consumed, the message is no longer in the message queue)

(2) There is no dependency on time between the sender and the receiver, 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

(3) The receiver must answer the queue successfully after receiving the message successfully

Features of Pub/sub

(1) Each message can have more than one consumer

(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 persistent subscription. This way, even if the Subscriber is not activated (running), it can receive the message from the publisher.

2. Installing ACTIVEMQ

IBM's WebSphere MQ provides a 90-day trial version, although WebSphere MQ was used in the project, but I did not study it carefully, and I chose to play or ACTIVEMQ.

Go to http://activemq.apache.org/activemq-5130-release.html download 5.13.0, I use the Windows system, unzip into the home directory, run Activemq.bat on the line if the console appears java.lang.UnsupportedClassVersionError:Unsupported major.minor version 51.0 is a problem with JDK versions, The jar provided by the official website is compiled with build-jdk:1.7.0_80, your Jdk is low, simple way to install jdk1.7, set the home directory environment variable

The use of ACTIVEMQ is described later ...

JMS Notes (i)

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.