简体   繁体   English

IBM MQ 服务器对消息进行编码

[英]IBM MQ server encodes messages

I'm sending XML to an IBM MQ Queue that contains a CDATA section.我将 XML 发送到包含 CDATA 部分的 IBM MQ 队列。 That CDATA section contains these special characters: $§)#ÜÖ&!^ .该 CDATA 部分包含这些特殊字符: $§)#ÜÖ&!^ For some reason, they are showing up within the MQ Queue as $�)#��&!^ .出于某种原因,它们在 MQ 队列中显示为$�)#��&!^ This causes the other send to take it off the queue with these characters and ending up having an invalid signature because the messages no longer match up.这会导致另一个发送使用这些字符将其从队列中取出,并最终获得无效签名,因为消息不再匹配。

We've verified that the message when we do a .Put() does contain an XML string with those special characters.我们已经验证了当我们执行 .Put .Put()时的消息确实包含带有这些特殊字符的 XML 字符串。 I've ensured that the message has .CharacterSet property assigned to it that matches what we will eventually pull off the queue.我已确保该消息具有分配给它的.CharacterSet属性,该属性与我们最终将退出队列的内容相匹配。

What other places can possibly be auto-encoding the special characters when it's put on the queue?当特殊字符被放入队列时,还有哪些其他地方可以自动编码特殊字符? Our application is in a .NET windows environment, but the MQ server is on a Linux box.我们的应用程序在 .NET windows 环境中,但 MQ 服务器在 Linux 盒子上。 Is this something to consider?这是要考虑的事情吗?

string xmlMsg = "<message><data><![CDATA[<value>$§)#ÜÖ&amp;!^</value>]]</data></message>"; // This is in a CDATA section.
mQMessage = new MQMessage
{
    CharacterSet = 1208,
};

mQMessage.WriteBytes(xmlMsg);

_queue.Put(mQMessage);

By default MQ doesn't change the character set of your message.默认情况下,MQ 不会更改消息的字符集。 So by default it is the responsibility of the sending and receiving applications to agree and maintain a character set that suits both.因此默认情况下,发送和接收应用程序有责任同意并维护适合两者的字符集。

You can request MQ to do character set conversion either in the receiving application, when that calls a get, or on the sender channels when the message is transmitted between queue managers.您可以请求 MQ 在调用 get 时在接收应用程序中进行字符集转换,或者在队列管理器之间传输消息时在发送方通道上进行字符集转换。 But even if you request character set conversion from MQ, it is still the sending applications responsibility to actually write the data into the message using the character set the application is setting on the MQ message header.但是,即使您从 MQ 请求字符集转换,使用应用程序在 MQ 消息 header 上设置的字符集将数据实际写入消息仍然是发送应用程序的责任。

Based on your code it seems your sending application doesn't use the correct character set when it writes the bytes to the message.根据您的代码,您的发送应用程序在将字节写入消息时似乎没有使用正确的字符集。 If you use WriteBytes, you need to manually convert the string into bytes using the desired character set.如果使用 WriteBytes,则需要使用所需的字符集手动将字符串转换为字节。

I'd suggest you to use the WriteString method, which is designed to use the chracter set specified in the CharacterSet property:我建议您使用 WriteString 方法,该方法旨在使用 CharacterSet 属性中指定的字符集:

The WriteString method converts from Unicode to the character set encoded in CharacterSet. WriteString 方法从 Unicode 转换为在 CharacterSet 中编码的字符集。 If CharacterSet is set to its default value, MQC.MQCCSI_Q_MGR, which is 0, no conversion takes place and CharacterSet is set to 1200. If you set CharacterSet to some other value, WriteString converts from Unicode to the alternate value.如果 CharacterSet 设置为其默认值 MQC.MQCCSI_Q_MGR,即 0,则不进行任何转换,并且 CharacterSet 设置为 1200。如果将 CharacterSet 设置为其他值,WriteString 将从 Unicode 转换为备用值。

https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111220_.htm https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111220_.htm

And by the way, for debugging character set issues you have to be very careful what tools you use to check the message, as your tool needs to be able to interpret the character set of the message.顺便说一句,对于调试字符集问题,您必须非常小心使用什么工具来检查消息,因为您的工具需要能够解释消息的字符集。 For example MQ Explorer uses the character set of your workstation where you run it, so it will show every message with that one character set, so is not suitable to debug these issues.例如,MQ Explorer 使用您运行它的工作站的字符集,因此它会使用该字符集显示每条消息,因此不适合调试这些问题。 The best is to get the message off the queue without asking the QM for conversion with rfhutil for example, save it to a file and look at it with a hex editor.最好的办法是在不要求 QM 使用 rfhutil 进行转换的情况下将消息从队列中取出,例如,将其保存到文件中并使用十六进制编辑器查看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM