0

Regarding: “Sending response back to the out/reply queue.”

There is a requirement to send the response back to a different queue (reply queue). While sending the response, we have to use the correlation and message id from the request message and pass it to the reply queue as header. I suspect the format of correlation/message id is wrong.

While reading the message, the correlation id and message id format are as below:

MessageId = “ID:616365323063633033343361313165646139306638346264” CorrelationId = “ID:36626161303030305f322020202020202020202020202020”

While sending the back to out/reply queue, we are passing these ids as below:

ITextMessage txtReplyMessage = sessionOut.CreateTextMessage();

txtReplyMessage.JMSMessageID = “616365323063633033343361313165646139306638346264”; 
txtReplyMessage.JMSCorrelationID = “36626161303030305f322020202020202020202020202020”; 
txtReplyMessage.Text = sentMessage.Contents;
txtReplyMessage.JMSDeliveryMode = DeliveryMode.NonPersistent;
txtReplyMessage.JMSPriority = sentMessage.Priority;
messagePoducerOut.Send(txtReplyMessage);

Please note:

  1. With the XMS.NET library, we need to pass the correlation and message id in string format as per shown above

  2. With MQ API’s (which we were using earlier) passing the correlation and message ids we use to send in bytes format like below:

    MQMessage queueMessage = new MQMessage();

                string[] parms = document.name.Split('-');
                queueMessage.MessageId = StringToByte(parms[1]);
                queueMessage.CorrelationId = StringToByte(parms[2]);
                queueMessage.CharacterSet = 1208;
                queueMessage.Encoding = MQC.MQENC_NATIVE;
                queueMessage.Persistence = 0;  // Do not persist the replay message.
                queueMessage.Format = "MQSTR   ";
                queueMessage.WriteString(document.contents);
                queueOut.Put(queueMessage);
                queueManagerOut.Commit();
    

Please help to troubleshoot the problem.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
b_patil
  • 1
  • 2

2 Answers2

0

Troubleshooting is a bit difficult because you haven’t clearly specified the trouble (is there an exception, or is the message just not be correlated successfully?). In your code you have missed to add the “ID:” prefix. However, to address the requirements, you should not need to bother too much about what is in this field, because you simply need to copy one value to the other:

txtReplyMessage.JMSCorrelationID = txtRequestMessage.JMSMessageID
Nine Friends
  • 156
  • 5
  • Yeah, the message was not correlated successfully while sending response back to the outbound queue. – b_patil Sep 16 '22 at 08:41
  • That did not work. – b_patil Sep 16 '22 at 10:19
  • What was your change? Have you added "ID:" in your code or have you copied the message Id from the request message to the correl Id of the reply message? – Nine Friends Sep 16 '22 at 11:43
  • Yeah, I added the "ID:" as prefix and set the correlation id as message id from the request message. Didn't set the message id for response message. – b_patil Sep 16 '22 at 13:03
  • Sorry, this is a bit confusing. If you set the message id from the request message, you don't need to add the "ID:"anymore as it is already in there. Adding "ID:" was just a comment to your code sample where you set the id hard coded. – Nine Friends Sep 16 '22 at 13:58
  • Sorry for confusion. I am setting the Message Id of request to correlation id of response. It looks like: "ID:633936333161363033356366313165646139306638346264" While debugging we got to know that the Outbound queue expecting Message id and correlation id same as request. When I set the message id, the MQ is overriding it. Since the Message id of request and response are not matching, its failing, – b_patil Sep 16 '22 at 17:32
  • The requester should only filter for the correl id. This is the common pattern for request/response. – Nine Friends Sep 16 '22 at 18:47
  • It is not possible to set MessageID to a sending message. It will be set by infrastructure. – Talijanac Sep 28 '22 at 09:48
  • @Talijanac, please note, I have explicitly NOT suggested setting the MessageID. but the CorrelId only (to the value of the MessageId of the request message). The requester should only filter for matching CorrelId when receiving the response. – Nine Friends Sep 28 '22 at 15:35
  • @Nine Friends sorry I wasn't clear. It was not a reply, but a statement about JMS/XMS. Not that you should not set JMSMessageID, but you are not even able to do it. JMS is somewhat stupidly designed and shares interfaces between clients and driver writers. So clients are able to see some internal methods which do nothing for client code like setJMSMessageID (a method indented for driver writers). – Talijanac Sep 28 '22 at 16:29
  • 1
    There are two standard practices for correlating messages are: 1) by sharing the same correlationID between all messages; 2) by having messageID of request message in a correlationID header of reply message, obviously used in request-reply logic. – Talijanac Sep 28 '22 at 16:33
0

A bit unclear what the issue is. Are you able to run the provided examples in the MQ tools/examples? This approach uses tmp queues(AMQ.*) as JMSReplyTo

Start the "server" application first.

Request/Response Client: "SimpleRequestor" Request/Response Server: "SimpleRequestorServer"

You can find the exmaples at the default install location(win): "C:\Program Files\IBM\MQ\tools\dotnet\samples\cs\xms\simple\wmq"

The "SimpleMessageSelector" will show how to use the selector pattern.

Note the format on the selector: "JMSCorrelationID = '00010203040506070809'"

IBM MQ SELECTOR

kaseidu
  • 173
  • 1
  • 6