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 |
// 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);
// 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());
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.