In-depth analysis of a JMS message (message header)

Source: Internet
Author: User

A message object has three parts: the message header, the message attribute, and the message data itself. It is called a payload or message body. Messages can carry important data or are only used for System Event Notifications. In most cases, messages are used as notifications and data-carrying tools at the same time. Let's talk about the message header first.

Each JMS message has a set of standard message headers. Each message header is identified by a set of value functions and value assignment function methods. The names of these methods follow the procedures setjms

public interface Message {    public Destination getJMSDestination() throws JMSException;    public void setJMSDestination(Destination destination) throws JMSException;    public int getJMSDeliveryMode() throws JMSException    public void setJMSDeliveryMode(int deliveryMode) throws JMSException;    public String getJMSMessageID() throws JMSException;    public void setJMSMessageID(String id) throws JMSException;    public long getJMSTimestamp() throws JMSException‘    public void setJMSTimestamp(long timestamp) throws JMSException;    public long getJMSExpiration() throws JMSException;    public void setJMSExpiration(long expiration) throws JMSException;    public boolean getJMSRedelivered() throws JMSException;    public void setJMSRedelivered(boolean redelivered) throws JMSException;    public int getJMSPriority() throws JMSException;    public void setJMSPriority(int priority) throws JMSException;    public Destination getJMSReplyTo() throws JMSException;    public void setJMSReplyTo(Destination replyTo) throws JMSException;    public String getJMScorrelationID() throws JMSException;    public void setJMSCorrelationID(String correlationID) throws JMSException;    public byte[] getJMSCorrelationIDAsBytes() throws JMSException;    public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException;    public String getJMSType() throws JMSException;    public void setJMSType(String type) throws JMSException;}

JMS message headers can be divided into two categories: automatically assigned message headers and developers' assigned message headers.

1. automatically assigned Message Headers

Most JMS message headers are automatically assigned. When a message is sent, the value of the message header is set by the JMS provider. Therefore, developers use setjms

Jmsdeliverymode

In JMS, there are two transmission modes: Persistent mode and non-persistent mode. A persistent message should be sent "once and only once", which means that if the JMS provider fails, the message will not be lost; it will be sent again after the server returns to normal. A non-persistent message is sent only once, which means that if the JMS provider fails, the message may be lost permanently. In both persistent and non-persistent transmission modes, the message server does not send a message more than once to the same message sender.

Int deliverymode = message. getjmsdeliverymode (); If (deliverymode = javax. JMS. deliverymode. persistent) {// persistence ......} else {// deliverymode. non_persistent non-persistent ......}

The transfer mode can be set using the setjmsdeliverymode () method on the producer (that is, topicpublisher or queuesender. Once the transmission mode is set for messageproducer, it applies to all messages sent by the producer. The default value is persistent ):

// Set the JMS transmission mode topicpublisher = topicsession. createpublisher (topic); topicpubiisher. setdeliverymode (delivermode. non_persistent) on the message producer );


In-depth analysis of a JMS message (message header)

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.