开发者

How to use SetBytesProperty and GetBytesProperty in WebSphere MQ?

开发者 https://www.devze.com 2023-04-12 03:08 出处:网络
I have a problem with SetBytesProperty / GetBytesProperty methods pair on MQMessage class (I\'m using WebSphere MQ Client 7.0.1.6). I can successfully send sbyte array in property to queue but once I

I have a problem with SetBytesProperty / GetBytesProperty methods pair on MQMessage class (I'm using WebSphere MQ Client 7.0.1.6). I can successfully send sbyte array in property to queue but once I try to get it back in read message I always get null.

Here is the simplest code I use to reproduce the issue.

[TestFixture]
public class MQQueueTests {

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

    [Test]
    public void PutAndGetMessage() {
        Environment.SetEnvironmentVariable("MQCCSID", "43开发者_运维百科7");
        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();
        }
    }
}

Something is passed in message property to queue - I can see something in WebSphere MQ Explorer on the server but it doesn't look like my passed array (it even change over time when new messages are received):

How to use SetBytesProperty and GetBytesProperty in WebSphere MQ?

When I turn on tracing (strmqtrc) on MQ Client I can see the same value wrote and read by the client:

This is present in log when putting message to the queue:

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>  

This is present in log when getting message from the queue (I removed some data to make it shorter but significant part is exactly as in log):

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....

So in both sending and receiving I see the same correct byte array. But in .NET code the value of the property is null:

How to use SetBytesProperty and GetBytesProperty in WebSphere MQ?

Every other GetXXXProperty and SetXXXProperty method pair works without any problem.

Edit:

I validated that it doesn't work on multiple computers running same version of WebSphere MQ clients and I also validated that it doesn't work with another code. It works if I rewrite the test to Java and use Java API instead!

I also have problems with sending any property in message targeted to MQTopic - I get MQException : MRQC_HEADER_ERROR. Again it works in Java without problem.


I am able to get the value. I can see the returned array has the same values as the ones in the sent message. Here is the C# snippet I used.

                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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号