MQMessage class
This class represents an IBM MQ message. It includes properties to encapsulate the IBM MQ message descriptor (MQMD), and provides a buffer to hold the application-defined message data.
The class includes Write methods to copy data from an ActiveX application to an MQMessage object. Similarly, the class includes Read methods to copy data from an MQMessage object to an ActiveX application. The class manages the allocation and deallocation of memory for the buffer automatically. The application does not have to declare the size of the buffer when an MQMessage object is created because the buffer grows to accommodate data written to it.
We cannot place a message onto an IBM MQ queue if the buffer size exceeds the MaximumMessageLength property of that queue.
After it has been constructed, an MQMessage object can be Put onto an IBM MQ queue using the MQQueue.Put method. This method takes a copy of the MQMD and message data portions of the object and places that copy on the queue. The application can therefore modify or delete an MQMessage object after the Put, without affecting the message on the IBM MQ queue. The queue manager can adjust some of the fields in the MQMD when it copies the message on the IBM MQ queue.
An incoming message can be read into an MQMessage object using the MQQueue.Get method. This replaces any MQMD or message data that might already have been in the MQMessage object with values from the incoming message. It adjusts the size of the data buffer of the MQMessage object to match the size of the incoming message data.
Containment
Messages are contained by the MQSession class.
Creation
New creates an MQMessage object. Its Message Descriptor properties are initially set to default values, and its Message Data buffer is empty.
Syntax
Dim msg As New MQMessageor
Set msg = New MQMessage
Properties
The control properties are:- CompletionCode property
- DataLength property
- DataOffset property
- MessageLength property
- ReasonCode property
- ReasonName property
- AccountingToken property
- AccountingTokenHex property
- ApplicationIdData property
- ApplicationOriginData property
- BackoutCount property
- CharacterSet property
- CorrelationId property
- CorrelationIdHex property
- Encoding property
- Expiry property
- Feedback property
- Format property
- GroupId property
- GroupIdHex property
- MessageData property
- MessageFlags property
- MessageId property
- MessageIdHex property
- MessageSequenceNumber property
- MessageType property
- Offset property
- OriginalLength property
- Persistence property
- Priority property
- PutApplicationName property
- PutApplicationType property
- PutDateTime property
- ReplyToQueueManagerName property
- ReplyToQueueName property
- Report property
- TotalMessageLength property
- UserId property
Methods
- ClearErrorCodes method
- ClearMessage method
- Read method
- ReadBoolean method
- ReadByte method
- ReadDecimal2 method
- ReadDecimal4 method
- ReadDouble method
- ReadDouble4 method
- ReadFloat method
- ReadInt2 method
- ReadInt4 method
- ReadLong method
- ReadNullTerminatedString method
- ReadShort method
- ReadString method
- ReadUInt2 method
- ReadUnsignedByte method
- ReadUTF method
- ResizeBuffer method
- Write method
- WriteBoolean method
- WriteByte method
- WriteDecimal2 method
- WriteDecimal4 method
- WriteDouble method
- WriteDouble4 method
- WriteFloat method
- WriteInt2 method
- WriteInt4 method
- WriteLong method
- WriteNullTerminatedString method
- WriteShort method
- WriteString method
- WriteUInt2 method
- WriteUnsignedByte method
- WriteUTF method
Property access
All properties can be read at any time.
The control properties are read-only, except for DataOffset which is read-write. The Message Descriptor properties are all read-write, except BackoutCount and TotalMessageLength which are both read-only.
Note however that some of the MQMD properties might be modified by the queue manager when the message is put onto an IBM MQ queue. See the fields in MQMD for details of how they might be modified.
Data conversion
We can pass binary data to an IBM MQ message by setting the CharacterSet property to match the Coded Character Set Identifier of the queue manager (MQCCSI_Q_MGR), and passing the data to the message as a string. If the string needs to include Unicode or ASCII code numbers, we can use the chr$ function to convert them to string format.
The Read and Write methods perform data conversion. They convert between the ActiveX internal formats, and the IBM MQ message formats as defined by the Encoding and CharacterSet properties from the message descriptor. When writing a message, set values into Encoding and CharacterSet that match the characteristics of the recipient of the message before issuing a Write method. When reading a message, this step is not normally required because these values will have been set from those in the incoming MQMD.
This is an additional data conversion step that happens after any conversion performed by the MQQueue.Get method.