How to set the JMSCorrelationID and correlate with JMSMessageID with a Camel client and a IBMMQ broker

1.3k Views Asked by At

I have a Camel client using the JMS Component to connect with IBMMQ.

I need to

  • Send a JMSCorrelationID with a fixed value.
  • Correlate the Reply message by JMSMessageID.

My configuration is:

.setHeader("CamelJmsDestinationName", "queue:///requestQueue.AQ?targetClient=1")
.setHeader("JMSCorrelationID", "SomeValue")
.to("jms:queue:requestQueue.AQ?useMessageIDAsCorrelationID=true&replyTo=ResponseQueue")

The issue is that JMSCorrelationID is null when useMessageIDAsCorrelationID=true

  JMSMessageID:     ID:c3e2d840d8d4e3f14040404040404040d95c7873193bef06
  JMSTimestamp:     1614870096440
  JMSCorrelationID: null

When useMessageIDAsCorrelationID=false the JMSCorrelationID is set as intended, but I get a timeout on correlation. How to use both?

1

There are 1 best solutions below

0
On

As a way around the issue I made the following changes to the .to() endpoint options:

  • exchangePattern=InOnly
  • includeSentJMSMessageID=true

Then the message is sent with a JMSCorrelationID, but without waiting on the reply. Thereafter I set a pollEnrich() dynamically with a simple expression using the JMSMessageID created by the broker which is filtered by a JMS Selector:

  • selector=JMSMessageID='${header.JMSMessageID}

The Camel route:

.setHeader("CamelJmsDestinationName", "queue:///requestQueue.AQ?targetClient=1")
.setHeader("JMSCorrelationID", "SomeValue")
.to("jms://RequestQueue?useMessageIDAsCorrelationID=false&exchangePattern=InOnly&replyTo=ReplyQueue&includeSentJMSMessageID=true")
.pollEnrich().simple("jms://ReplyQueue?selector=JMSMessageID='${header.JMSMessageID}').timeout(20000)
.log("${body}")