读取 MQ 消息的 header

Read the header of an MQ message

我收到一条来自 MQ 的消息,代码如下

MQQueue queue = mqManager.AccessQueue(queueName, openOptions);

MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_WAIT;
gmo.WaitInterval = MQC.MQWI_UNLIMITED;

queue.Get(message, gmo);

string message = message.ReadString(message.MessageLength);

问题是我还需要访问此邮件的 header 信息。即在 header 信息中找到的发送消息的 userId。如何访问消息的 header 信息?

访问 Userid property of MQMessage - 即 message.UserId

public string UserId { get; set; }
UserId is part of the identity context of the message. The queue manager generally provides the value. You can override the value if you have authority to set the identity context.