問題描述
Cara menghapus informasi header pesan di pesan yang dikelompokkan WebSphere MQ saat menerima di .Net client (How to remove the message header informations in WebSphere MQ grouped message while receving in .Net client)
I am trying to recevie logically grouped messages from an remote MQ using .Net client using native api [amqmdnet ‑ WebSphere MQ Classes for .NET], which was put by java client using native api.
While we are getting the logically grouped messages we are seeing some header information in all the messages in that group which will be showing differently in each editors, [notepad++, editplus etc.]
The below specified header information's is appended in every logical message in that group something like "MDE "
We are using the getmessageoptions
, openoptions
as below,
mintMQQueueOpenOptions = IBM.WMQ.MQC.MQOO_INPUT_SHARED + IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING
mobjMQGetMessageOptions = New MQGetMessageOptions
mobjMQGetMessageOptions.Options = IBM.WMQ.MQC.MQGMO_NO_SYNCPOINT + IBM.WMQ.MQC.MQGMO_FAIL_IF_QUIESCING
'mobjMQGetMessageOptions.Options = mobjMQGetMessageOptions.Options + MQC.MQGMO_LOGICAL_ORDER 'Or MQC.MQGMO_ALL_MSGS_AVAILABLE
Code snippet to read the all the logical message in that group,
'=================================
' INTANTIATE THE MQ MESSAGE OBJECT
objMQMessage = New MQMessage
objMQMessage.Format = MQC.MQFMT_STRING
'=================================
' CLEAR THE MESSAGE VARIABLE
strMQMessage = ""
Do
'============================
' GET THE MESSAGE FROM THE MQ
mobjMQQueue.Get(objMQMessage, mobjMQGetMessageOptions)
'============================
' READ THROUGH THE MESSAGE
strMQMessage += objMQMessage.ReadString(objMQMessage.MessageLength)
'============================
' SET GMO.MATCHOPTIONS TO GROUP ID, INITIALLY IT WAS SET TO "MQC.MQMO_NONE"
mobjMQGetMessageOptions.MatchOptions = MQC.MQMO_MATCH_GROUP_ID
'============================
' DO UNTIL ‑ MESSAGE IS THE LAST IN THE GROUP OR THE GROUP CONSISTS OF ONLY ONE MESSAGE.
Loop While (mobjMQGetMessageOptions.GroupStatus <> MQC.MQGS_LAST_MSG_IN_GROUP)
'====================================
' COLLECT THE MESSAGE IN AN ARRAYLIST
If Not String.IsNullOrEmpty(strMQMessage) Then objMQMessageList.Add(strMQMessage)
'============================
' COMMIT THE FETCH OPERATION
mobjMQQueueManager.Commit()
How we can remove this header information from each message?
‑‑‑‑‑
參考解法
方法 1:
The MQMDE
contains MQMD fields that exist in the version‑2 MQMD, but not in the version‑1 MQMD. The Infocenter topic Overview for MQMD describes how the MQMD
version affects behavior of the GET call:
On the MQGET call, if the application provides a version‑1 MQMD, the queue manager prefixes the message returned with an MQMDE, but only if one or more of the fields in the MQMDE has a non‑default value. The Format field in MQMD will have the value MQFMT_MD_EXTENSION to indicate that an MQMDE is present.
Based on this, I would suggest providing a Version 2 MQMD
. Perhaps this will solve the problem:
'=================================
' INTANTIATE THE MQ MESSAGE OBJECT
objMQMessage = New MQMessage
objMQMessage.Version = 2
objMQMessage.Format = MQC.MQFMT_STRING
'=================================
Since the objMQMessage
is reused for successive calls, you may need to set the version before each GET.
The IBM MQ Knowledge Center page "MQMDE ‑ Message descriptor extension > Overview for MQMDE" also has some useful information on the topic:
Usage: Applications that use a version‑2 MQMD will not encounter an MQMDE structure. However, specialized applications, and applications that continue to use a version‑1 MQMD, might encounter an MQMDE in some situations. The MQMDE structure can occur in the following circumstances:
- Specified on the MQPUT and MQPUT1 calls
- Returned by the MQGET call
- In messages on transmission queues
(by user1791681、T.Rob)