2012-08-15 111 views

回答

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用作消息选择的correlationId。

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

3)在所述服务器应用(其处理请求消息),发送响应消息时,只复制请求消息发送到响应消息的的correlationID的MESSAGEID。

responseMsg.CorrelationId = requestMsg.MessageId; 
+0

谢谢你的回答。如果我在发送消息之前设置了MQC.MQRO_COPY_MSG_ID_TO_CORREL_ID选项,而不是getMsg.CorrelationId = correlationId ;? – sada 2012-08-16 06:02:43

+0

请参阅我上面的编辑。 – Shashi 2012-08-16 07:16:01

+0

非常感谢。 – sada 2012-08-17 19:49:11