JMS properties

When storing JMS property fields in an MQeMsgObject, the <name, value> format used by the JMS properties corresponds very closely to the format of data in an MQeFields object:
Table 1. JMS property fields and the MQeFields object
Property type Corresponding MQeFields object
Application-specific MQe.MQe_JMS_PROPERTIES
Standard (JMSX_name) MQe.MQe_JMSX_PROPERTIES
Provider-specific (JMS_provider_name) MQe.MQe_JMS_PS_PROPERTIES
Three MQeFields objects, corresponding to the three types of JMS property, application-specific, standard, and provider-specific are used to store the <name, value> pairs stored as JMS message properties.
These three MQeFields objects are then embedded in the MQeMsgObject with the following names:
  • MQe.MQe_JMS_PROPERTIES, application-specific
  • MQe_MQe_JMSX_PROPERTIES, standard properties
  • MQe.MQe_JMS_PS_PROPERTIES, provider-specific
Note that MQe does not currently set any provider specific properties. However, this field is used to enable MQe to handle JMS messages from other providers, for example MQ.
The following code fragment creates an MQe JMS text message by adding the required fields to an MQeMsgObject:
// create an MQeMsgObject
  MQeMsgObject msg = new MQeMsgObject();

  // set the JMS version number
  msg.putShort(MQe.MQe_JMS_VERSION, (short)1);
  // and set the type of JMS message this MQeMsgObject contains
  msg.putAscii(MQeJMSMsgFieldNames.MQe_JMS_CLASS, "jms_text");

  // set message priority and exipry time - these are mapped to
    JMSPriority and JMSExpiration
  msg.putByte(MQe.Msg_Priority, (byte)7);
  msg.putLong(MQe.Msg_ExpireTime, (long)0);

  // store JMS header fields with no MQe
    equivalents in an MQeFields object
  MQeFields headerFields = new MQeFields();
  headerFields.putBoolean(MQeJMSMsgFieldNames.MQe_JMS_REDELIVERED,
                    false);
  headerFields.putAscii(MQeJMSMsgFieldNames.MQe_JMS_TYPE,
                  "testMsg");
  headerFields.putInt(MQeJMSMsgFieldNames.MQe_JMS_DELIVERYMODE,
  Message.DEFAULT_DELIVERY_MODE);
  msg.putFields(MQeJMSMsgFieldNames.MQe_JMS_HEADER,
              headerFields);

  // add an integer application-specific property
  MQeFields propField = new MQeFields();
  propField.putInt("anInt", 12345);
  msg.putFields(MQeJMSMsgFieldNames.MQe_JMS_PROPERTIES,
              propField);

  // the provider-specific and JMSX properties are blank
  msg.putFields(MQeJMSMsgFieldNames.MQe_JMSX_PROPERTIES,
            new MQeFields());
  msg.putFields(MQeJMSMsgFieldNames.MQe_JMS_PS_PROPERTIES,
            new MQeFields());

  // finally add a text message body
  String msgText = 
      "A test message to MQe JMS";
  byte[] msgBody = msgText.getBytes("UTF8");
  msg.putArrayOfByte(MQeJMSMsgFieldNames.MQe_JMS_BODY,
                     msgBody);

  // send the message to an MQe Queue
  queueManager.putMessage(null, 
                    "SYSTEM.DEFAULT.LOCAL.QUEUE",
                    msg, null, 0);
Now, you use JMS to receive the message and print it:
// first set up a QueueSession, then...
  Queue queue = session.createQueue
    ("SYSTEM.DEFAULT.LOCAL.QUEUE");
  QueueReceiver receiver = session.createReceiver(queue);
  
  // receive a message
  Message rcvMsg = receiver.receive(1000);

  // and print it out
  System.out.println(rcvMsg.toString());
This gives:
   HEADER FIELDS
  -----------------------------
   JMSType:          testMsg
   JMSDeliveryMode:  2
   JMSExpiration:    0
   JMSPriority:      7
   JMSMessageID:     ID:00000009524cf094000000f07c3d2266
   JMSTimestamp:     1032876532326
  JMSCorrelationID: null
  JMSDestination:   null:SYSTEM.DEFAULT.LOCAL.QUEUE
   JMSReplyTo:       null
   JMSRedelivered:   false

   PROPERTY FIELDS (read only)
  ------------------------------
   JMSXRcvTimestamp : 1032876532537
   anInt : 12345

   MESSAGE BODY (read only)
------------------------------------------------------------------
  A test message to MQe JMS

Note that JMS sets some of the JMS message fields, for example JMSMessageID, JMSXRcvTimestamp internally.


Terms of use | WebSphere software

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