【问题标题】:How to use SetBytesProperty and GetBytesProperty in WebSphere MQ?如何在 WebSphere MQ 中使用 SetBytesProperty 和 GetBytesProperty?
【发布时间】:2011-10-13 17:57:39
【问题描述】:

MQMessage 类上的 SetBytesProperty / GetBytesProperty 方法对存在问题(我使用的是 WebSphere MQ 客户端 7.0.1.6)。我可以成功地将属性中的sbyte 数组发送到队列,但是一旦我尝试在读取消息中取回它,我总是会得到null

这是我用来重现问题的最简单的代码。

[TestFixture]
public class MQQueueTests {

    public const string MessageContent = "<test>This is test message</test>";

    [Test]
    public void PutAndGetMessage() {
        Environment.SetEnvironmentVariable("MQCCSID", "437");
        var properties = new Hashtable
                             {
                                 {MQC.HOST_NAME_PROPERTY, "TestServer"},
                                 {MQC.CHANNEL_PROPERTY, "Test.Channel"},
                                 {MQC.PORT_PROPERTY, 1415} 
                             };

        using (var manager = new MQQueueManager("Test.Queue.Manager", properties)) {
            using (MQQueue queue = manager.AccessQueue("Test.Queue", 
                MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF)) {

                MQMessage message = new MQMessage();
                message.SetBytesProperty("testBytesValue", 
                   new sbyte[] { 8, 12, 22, 48, 68, 71, 92, 104 });
                message.WriteUTF(MessageContent);
                queue.Put(message);

                MQMessage readMessage = new MQMessage();
                queue.Get(readMessage);

                sbyte[] array = readMessage.GetBytesProperty("testBytesValue");
                Assert.IsNotNull(array);  // <-- FAILS!

                Assert.AreEqual(MessageContent, readMessage.ReadUTF());

                queue.Close();
            }
            manager.Disconnect();
        }
    }
}

消息属性中传递了一些东西到队列 - 我可以在服务器上的 WebSphere MQ Explorer 中看到一些东西,但它看起来不像我传递的数组(它甚至在收到新消息时会随着时间而改变):

当我在 MQ 客户端上打开跟踪 (strmqtrc) 时,我可以看到客户端写入和读取的值相同:

将消息放入队列时会出现在日志中:

Data:-
 0x00000000 026B5878 3C 75 73 72 3E 3C 74 65 73 74 42 79 74 65 73 56 : <usr><testBytesV
 0x00000000 026B5888 61 6C 75 65 20 64 74 3D 22 62 69 6E 2E 68 65 78 : alue dt="bin.hex
 0x00000000 026B5898 22 20 3E 30 38 30 63 31 36 33 30 34 34 34 37 35 : " >080c163044475
 0x00000000 026B58A8 63 36 38 3C 2F 74 65 73 74 42 79 74 65 73 56 61 : c68</testBytesVa
 0x00000000 026B58B8 6C 75 65 3E 3C 2F 75 73 72 3E 20 20             : lue></usr>  

从队列中获取消息时,这会出现在日志中(我删除了一些数据以使其更短,但重要部分与日志中的完全相同):

Receiving Data:-

 0x00000000 1D2A5090 20 20 20 20 20 20 20 20 00 00 00 00 B8 04 00 00 :         ....¸...
 0x00000000 1D2A50A0 4C 00 00 00 3C 75 73 72 3E 3C 74 65 73 74 42 79 : L...<usr><testBy
 0x00000000 1D2A50B0 74 65 73 56 61 6C 75 65 20 64 74 3D 22 62 69 6E : tesValue dt="bin
 0x00000000 1D2A50C0 2E 68 65 78 22 20 3E 30 38 30 63 31 36 33 30 34 : .hex" >080c16304
 0x00000000 1D2A50D0 34 34 37 35 63 36 38 3C 2F 74 65 73 74 42 79 74 : 4475c68</testByt
 0x00000000 1D2A50E0 65 73 56 61 6C 75 65 3E 3C 2F 75 73 72 3E 20 20 : esValue></usr>  
 0x00000000 1D2A50F0 00 21 3C 74 65 73 74 3E 54 68 69 73 20 69 73 20 : .!<test>This is 
 0x00000000 1D2A5100 74 65 73 74 20 6D 65 73 73 61 67 65 3C 2F 74 65 : test message</te
 0x00000000 1D2A5110 73 74 3E 34 54 53 48 4D 00 00 00 34 00 00 00 01 : st>4TSHM...4....

所以在发送和接收中,我看到了相同的正确字节数组。但在 .NET 代码中,该属性的值为null

每个其他 GetXXXPropertySetXXXProperty 方法对都可以正常工作。

编辑:

我验证它不能在运行相同版本的 WebSphere MQ 客户端的多台计算机上工作,并且我还验证它不能与另一个代码一起工作。如果我将测试重写为 Java 并改用 Java API,它会起作用!

我在发送针对MQTopic 的消息中的任何属性时也遇到问题 - 我得到MQException : MRQC_HEADER_ERROR。它再次在 Java 中运行没有问题。

【问题讨论】:

    标签: c# .net ibm-mq


    【解决方案1】:

    我能够获得价值。我可以看到返回的数组与发送的消息中的值相同。这是我使用的 C# sn-p。

                    MQMessage message = new MQMessage();
                    message.SetBytesProperty("testBytesValue", new sbyte[] { 8, 12, 22, 48, 68, 71, 92, 104 });
                    message.WriteUTF(MessageContent);
                    queue.Put(message);
    
                    MQMessage readMessage = new MQMessage();
                    queue.Get(readMessage);
    
                    sbyte[] array = readMessage.GetBytesProperty("testBytesValue");
                    Console.Write(array);
    

    【讨论】:

    • 您能检查一下您使用的是什么版本的客户端和amqmdnet 库吗?我在两台机器上多次尝试了我的代码,我什至使用了客户端中安装的MQMessagePropertiesSample(默认情况下它不包含字节数组 - 我添加了它)。它从来没有用过,但如果我用 JUnit 用 Ja​​va 编写测试它就可以了!
    • 那是我以前写的程序,但无法回忆起我尝试过的客户端版本。但是我今天检查了 MQ v7016,我也得到了同样的错误,即返回的数组为空。值得致电 IBM 支持。
    猜你喜欢
    • 2016-01-27
    • 2013-01-09
    • 2015-10-10
    • 2010-10-28
    • 1970-01-01
    • 2012-03-09
    • 2015-09-09
    • 1970-01-01
    • 2010-11-24
    相关资源
    最近更新 更多