【问题标题】:Validating message(s) in IBM MQ in import and export queues在导入和导出队列中验证 IBM MQ 中的消息
【发布时间】:2014-11-12 22:00:45
【问题描述】:

我正在尝试编写2个方法来测试一个队列中发送的消息是否在另一个队列中接收。

Send 方法 - 发送消息,例如 - “Message 123” - 以导出具有唯一关联 ID 的队列。

获取方法

这个队列会有很多消息,但是我只想根据我的相关 ID 获取我从上面发送的消息。

根据相关ID检查消息的代码

      properties = new Hashtable();
       properties.Add(MQC.CONNECTION_NAME_PROPERTY, "connection name");
       properties.Add(MQC.TRANSPORT_PROPERTY, "transport type");
       properties.Add(MQC.CHANNEL_PROPERTY, "channel name"); 
       properties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_HANDLE_SHARE_BLOCK);



       mqGetMsgOpts = new MQGetMessageOptions();
       mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_WAIT | MQC.MQOO_INQUIRE;
       mqGetMsgOpts.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
       mqGetMsgOpts.WaitInterval = 3000; //3 secs wait time

我面临的问题是当我阅读消息时,我从导入队列中获取所有消息。

如何仅获取我发送的消息并验证导出队列中收到的消息是我的?

理论上是这样的

导入队列中的message.correlationid 与导出队列中的message.correlationid 匹配。

【问题讨论】:

    标签: c# ibm-mq


    【解决方案1】:

    您的 sn-p 在阅读消息时未显示设置 correlId。我有这个示例代码,它只获取与给定 correlId 匹配的消息。

    和之前一样,您的 sn-p 仍然有 MQC.MQOO_INQUIRE 对应于 MQGMOMQOO代表Open Options,而MQGMO代表Get message options

            try
            {
                importQ = qm.AccessQueue("Q2", MQC.MQOO_INPUT_SHARED | MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING);
    
                // Put one message. MQ generates correlid
                MQMessage mqPutMsg = new MQMessage();
                mqPutMsg.WriteString("This is the first message with no app specified correl id");
                importQ.Put(mqPutMsg);
    
                // Put another messages but with application specified correlation id
                mqPutMsg = new MQMessage();
                mqPutMsg.WriteString("This is the first message with application specified correl id");
                mqPutMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(strCorrelId);
                MQPutMessageOptions mqpmo = new MQPutMessageOptions();
                importQ.Put(mqPutMsg,mqpmo);
    
                mqPutMsg = new MQMessage();
    
                // Put another message with MQ generating correlation id
                mqPutMsg.WriteString("This is the second message with no app specified correl id");
                importQ.Put(mqPutMsg);
    
                // Get only the message that matches the correl id
                MQMessage respMsg = new MQMessage();
                respMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(strCorrelId);
                MQGetMessageOptions gmo = new MQGetMessageOptions();
                gmo.WaitInterval = 3000;
                gmo.Options = MQC.MQGMO_WAIT;
                gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
    
                importQ.Get(respMsg, gmo);
                Console.WriteLine(respMsg.ReadString(respMsg.MessageLength));
            }
    

    【讨论】:

    • 谢谢,我按照您提到的方式进行了操作,但是我不断收到此错误中的任何一个。 IBM.WMQ.MQException:MQRC_NO_MSG_AVAILABLE System.IO.EndOfStreamException:无法读取超出流的末尾。 -> 消息离开队列并由于数据长度变为 0 而抛出此消息,有什么想法吗?
    • MQRC_NO_MSG_AVAILABLE:在获取消息时检查您的代码中的匹配选项和 correlId。看起来指定的 correlId 可能与队列中任何消息的 correlid 都不匹配。 EndOfStreamException:似乎正在尝试读取空消息的数据。
    猜你喜欢
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 2022-09-29
    • 2021-06-09
    相关资源
    最近更新 更多