简体   繁体   中英

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

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?

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}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM