【问题标题】:Client filter message by CorrelationId客户端按 CorrelationId 过滤消息
【发布时间】:2012-08-16 15:15:33
【问题描述】:

即使该消息不是队列中的第一个消息,我是否可以通过其 CorrelationId 过滤并从队列中获取消息?

【问题讨论】:

    标签: c# ibm-mq


    【解决方案1】:

    是的。您必须在MQGetMessageOptions 上使用MQGMO_MATCH_CORREL_ID 匹配选项。

       MQMessage getMsg = new MQMessage();
    
       MQGetMessageOptions gmo = new MQGetMessageOptions();
       gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
    
       // Copy correlationID of the message you want to receive       
       getMsg.CorrelationId = correlationId;
    
       queue.Get(getMsg, gmo);
    

    编辑:

    CorrelationId 用于关联两条消息,通常是请求和回复消息。所以就这样搞定了。

    1) 客户端应用程序发送请求消息。发送消息后缓存发送消息的messageId。

    2) 将此 messageId 用作消息选择的相关 ID。

     recvdResponseMsg.CorrelationId = requestMsg.MessageId;
     gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
    

    3) 在处理请求消息的服务器应用程序中,发送响应消息时,只需将请求消息的messageId复制到响应消息的correlationId即可。

     responseMsg.CorrelationId = requestMsg.MessageId;
    

    【讨论】:

    • 感谢您的回答。如果我在发送消息之前设置 MQC.MQRO_COPY_MSG_ID_TO_CORREL_ID 选项而不是 getMsg.CorrelationId = correlationId; 是否也正确?
    猜你喜欢
    • 1970-01-01
    • 2014-05-10
    • 2022-06-20
    • 1970-01-01
    • 2019-04-08
    • 2012-11-02
    • 2018-09-08
    • 2013-02-21
    • 2010-11-05
    相关资源
    最近更新 更多