I made a java app that uses JMS to send messages to an MQ Queue. I set the message id and correlation id with the setJMSMessageId() and setJMSCorrelationId(). The messageId seems to be overwritten when the sending ends. I googled a bit, and seems that the server overwrites the messageId even when you send it.
The requirement for this app is that both messageId and correlationId have the same value when sent and when received. Isn't there anything I can do about this?
Note: I am using JDK 1.6, and a WAS 8.5 to deploy the app. This WAS communicates with a MQ Queue Manager.
The JMSCorrelationID provides a header for associating the current message with some previous message or application-specific ID. In most cases, the JMSCorrelationID will be used to tag a message as a reply to a previous message.
A correlation ID is used to correlate response messages with request messages when an application invokes a request-response operation. With WebSphere® MQ and WebSphere MQ JMS, you can correlate using either a correlation ID or a message ID.
JMS Request Reply is an asynchronous activity that is used to send a request to a JMS destination and wait for a response from the JMS client.
Message ids are reserved for the messaging system to set. You can read it and, e.g., log or even persist it, but nothing else. Esp., it's not supposed to be set by an application! The setter is there only when bridging between two messaging systems, i.e. when you receive a message from one messaging system X and forward it to a different messaging system Y. Then Y needs to be able to set the message id of that message object, even though Y has not created it, i.e. even though it's not Y's own implementation. There are several methods for this use case and it's causing a lot of confusion; it's best to just ignore them.
OTOH, correlation ids are for your application to use. A very common pattern is a request-response pair of messages, and this is the second source of confusion:
send
methods, and A stores this message id.There are a lot of other message exchange patterns, like one-request-many-replies or unsolicited messages, and the proper use of correlation ids is essential; but request-reply is by far the most common. That's why it's even suggested in the JavaDoc. Otherwise message ids have nothing to do with correlation ids. This is confusing for beginners. I even found it preferable to correlate messages with business keys instead of message ids.
Coming back to your question: as you set the correlation id before you send the message, and the message id is set by the messaging system when you send the message, there is no way in the JMS-API to make both values the same value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With