1

As described here: setting ReplyToQ attribute of MQMD of IBM MQ request message with Camel I managed to set ReplyToQ in MQMD of request properly in Camel Route, but I can't get the response in the same Route, with the IBM MQ Endpoint ("to") that I would like to use both for output (of request) and for input (of response), because it is matching wrong Correlation ID, like this:

The OUT message was not received within: 20000 millis due reply message with correlationID: Camel-ID-MYPC-62418-1518179436629-0-5 not received on destination: queue:///REPLYQ. Exchange[ID-MYPC-62418-1518179436629-0-4]

Namely, responding application sets CorrelationID (in MQMD) to the MessageID (from MQMD of the received request). How to make this scenario work?

I tried with useMessageIDAsCorrelationID, but this doesn't change much the result (responses are not consumed). Another try was to set MessageID of request to some fixed value (that would not be final solution), but I can't even do that. I added this:

        <setHeader headerName="JMSMessageID" id="_setHeader2">
            <constant>abcdefg</constant>
        </setHeader>
        <setHeader headerName="JMSCorrelationID" id="_setHeader3">
            <constant>abcdefg</constant>
        </setHeader>

but this only sets CorrelationID, and I still get such things:

The OUT message was not received within: 20000 millis due reply message with correlationID: abcdefg not received on destination: queue:///REPLYQ. Exchange[ID-MYPC-65151-1518190285422-0-3]

Complete route definition:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
    <bean class="org.apache.camel.component.jms.JmsComponent" id="websphere">
        <property name="connectionFactory">
            <bean class="com.ibm.mq.jms.MQConnectionFactory">
                <property name="transportType" value="1"/>
                <property name="hostName" value="hostname"/>
                <property name="port" value="port"/>
                <property name="queueManager" value="qmgr_name"/>
                <property name="channel" value="channel_name"/>
            </bean>
        </property>
    </bean>
    <!-- Define a traditional camel context here -->
    <camelContext id="camel" useBreadcrumb="false" xmlns="http://camel.apache.org/schema/spring">
        <route id="simple-route">
            <from id="request-file" uri="file://C:/mqdocuments/?fileName=request.txt"/>
            <log id="route-log" message=">>> ${body}"/>
            <setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
                <constant>queue://QM_TEST/INPUTQ?targetClient=1&amp;mdWriteEnabled=true&amp;mdReadEnabled=true</constant>
            </setHeader>
            <setHeader headerName="JMSMessageID" id="_setHeader2">
                <constant>abcdefg</constant>
            </setHeader>
            <setHeader headerName="JMSCorrelationID" id="_setHeader3">
                <constant>abcdefg</constant>
            </setHeader>
            <to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?replyTo=REPLYQ"/>
        </route>
    </camelContext>
</beans>
hdjur_jcv
  • 686
  • 1
  • 12
  • 30
  • Btw, last setHeader tag properly sets CorrelationID in MQMD of request message, but that doesn't help much, since responding application doesn't use that attribute of request message. – hdjur_jcv Feb 09 '18 at 15:42
  • And I would expect useMessageIDAsCorrelationID to be useful if I was to implement in Camel a responding service, that has to set CorrelationID of response to MessageID of received request, which is not the case here. – hdjur_jcv Feb 09 '18 at 16:10
  • Could you add the complete route definition? – thuri Feb 09 '18 at 16:57
  • Do you see actually see correct replyto properties in the MQMD header`? – Souciance Eqdam Rashti Feb 09 '18 at 21:34
  • @thuri Here you are, I updated the question with the whole route definition. – hdjur_jcv Feb 12 '18 at 12:19
  • In fact, I added the whole camel-context.xml, which contains not only the route definition, but the definition of mq jms bean that is used within. – hdjur_jcv Feb 12 '18 at 12:27
  • @Eqdam Rashti I see correct replyTo properties in MQMD header. If I point the camel route to a queue which is not consumed by the responding application, I can investigate the message placed by camel route in detail, and see that replyToQ is set OK, and replyToQMgr was OK from the start, since by default it is set to the qmgr where request is put. If I point the root to the intended queue (INPUTQ), responding application (MDB) puts response to intended reply queue (REPLYQ). So, as I said, this is not problem anymore, the problem is consuming the reply with the same camel route. – hdjur_jcv Feb 12 '18 at 12:32
  • Another idea is to use native mq java api, instead of jms, for QCF bean. Maybe that way I wouldn't face that problem. – hdjur_jcv Feb 12 '18 at 12:39
  • By that I mean using org.apacheextras.camel.component.wmq, instead of org.apache.camel.component.jms.JmsComponent. But anyway, if someone knows how to make it work with jms, I would appreciate to hear it. – hdjur_jcv Feb 12 '18 at 13:53
  • Not sure if I understand the route correctly. If you want to consume the response from the reply to queue you need to add some endpoint after the last . You could add a file endpoint for testing purposes. – thuri Feb 12 '18 at 19:20
  • I could do that, but in that case I need to get rid of InOut pattern behaviour first, that is trying to consume the response with the same endpoint that is used to produce the request. – hdjur_jcv Feb 13 '18 at 02:22
  • And I would like to utilize that behaviour if possible. – hdjur_jcv Feb 13 '18 at 02:26
  • useMessageIDAsCorrelationID flag should also be useful in my case of making a camel route that consumes an mq service provided by the responding mq application, if I was able to set it. Because if request msg CorrelationID in MQMD was set to the same value as its MessageID generated by a qmgr, that would be desired behaviour. – hdjur_jcv Feb 13 '18 at 08:50

1 Answers1

1

OK, this simple code actually works as explained here:

http://camel.apache.org/correlation-identifier.html

    <route id="simple-route">
        <from id="request-file" uri="file://C:/mqdocuments/?fileName=request464.txt"/>
        <log id="route-log-request" message="request: ${body}"/>
        <setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
            <constant>queue://QM_TEST/INPUTQ?targetClient=1</constant>
        </setHeader>
        <to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?useMessageIDAsCorrelationID=true&amp;replyTo=REPLYQ"/>
        <log id="route-log-response" message="response: ${body}"/>
    </route>

It prints out neatly response body to console output. I don't know why I was under impression that it doesn't work when I first tried it. So, to summarize both questions, the catch is in using useMessageIDAsCorrelationID and replyTo parameters in uri of a queue, as well as pattern="InOut" parameter of <to> endpoint.

hdjur_jcv
  • 686
  • 1
  • 12
  • 30