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 9. 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:

Note that WebSphere MQ Everyplace does not currently set any provider specific properties. However, this field is used to enable WebSphere MQ Everyplace to handle JMS messages from other providers, for example WebSphere MQ.

JMS message body

Regardless of the JMS message type, WebSphere MQ Everyplace stores the JMS message body internally as an array of bytes. For the currently supported message types, this byte array is created as follows:

Table 10. JMS message body

JMS message type Conversion
Bytes message ByteArrayOutputStream.toByteArray();
Object message <serialized object>.toByteArray();
Text message String.getBytes("UTF-8");

When the JMS message body is stored in an MQeMsgObject, this byte array is added directly to the MQeMsgObject with the name MQe.MQe_JMS_BODY.

The following code fragment creates a WebSphere MQ Everyplace 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 WebSphere MQ Everyplace 
		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 WebSphere MQ Everyplace JMS";
	byte[] msgBody = msgText.getBytes("UTF8");
	msg.putArrayOfByte(MQeJMSMsgFieldNames.MQe_JMS_BODY,
										 msgBody);
 
	// send the message to a WebSphere MQ Everyplace Queue
	queueManager.putMessage(null, 
										"SYSTEM.DEFAULT.LOCAL.QUEUE", 
										msg, null, 0);

Now, we 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 WebSphere MQ Everyplace JMS
 

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



© IBM Corporation 2002. All Rights Reserved