Examples

Message Properties - Examples

In all cases, a defined constant allows the property name to be carried in a single byte. For example, priority (if present) affects the order in which messages are transmitted, correlation ID triggers indexing of a queue for fast retrieval of information, expire time triggers the expiry of the message, and so on. Also, the default message dump command minimizes the size of the generated byte string for more efficient message storage and transmission.

The MQe Message ID and Correlation ID allow the application to provide an identity for a message. These are also used in interactions with the rest of the MQ family:
Java™
MQeMsgObject msgObj = new MQeMsgObject;
msgObj.putArrayOfByte( MQe.Msg_ID, MQe.asciiToByte( "1234" ));
C
rc = mqeFields_putArrayOfByte(hMsg,&exceptBlock, 
            MQE_MSG_MSGID,pByteArray,sizeByteArray);
Priority contains message priority values. Message priority is defined as in other members of the MQ family. It ranges from 9 (highest) to 0 (lowest):
Java
MQeMsgObject msgObj = new MQeMsgObject();
msgObj.putByte( MQe.Msg_Priority, (byte)8 );
C
rc = mqeFields_putByte(hsg,&exceptBlock, MQE_MSG_PRIORITY, (MQEBYTE)8);
Applications can create fields for their own data within messages:
Java
MQeMsgObject msgObj = new MQeMsgObject();
msgObj.putAscii( "PartNo", "Z301" );
msgObj.putAscii( "Colour", "Blue" );
msgObj.putInt( "Size", 350 );
C
MQeFieldsHndl hPartMsg;
MQeStringHndl hSize_FieldLabel;
rc = mqeFields_new(&exceptBlock,&hPartMsg);
rc = mqeString_newUtf8(&exceptBlock, 
                  &hSize_FieldLabel,"Size");

rc = mqeFields_putInt32(hPartMsg, 
                &exceptBlock,hSize_FieldLabel,350);
The priority of the message is used, in part, to control the order in which messages are removed from the queue. If the message does not specify any, then the queue default priority is used . This, unless changed, is 4. However, the application must interpret the different levels of priority.
In Java, you can extend the MQeMsgObject to include some methods that assist in creating messages, as shown in the following example:
package messages.order;
import com.ibm.mqe.*;

/*** This class defines the Order Request format */
public class OrderRequestMsg extends MQeMsgObject
{

  public OrderRequestMsg() throws Exception
  {
  }

 /*** This method sets the client number */
  public void setClientNo(long aClientNo) throws Exception
  {
    putLong("ClientNo", aClientNo);
  }

 /*** This method returns the client number */
  public long getClientNo() throws Exception
  {
    return getLong("ClientNo");
  }

To find out the length of a message, you can enumerate on the message as each data type has methods for getting its length.


Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.