1
votes

I checked several previous discussions but couldnt find the answer.

I am trying to achieve synchronous communicaiton using JMS back-channel (http://www.whishworks.com/blog/synchronous-communication-using-jms-back-channel). Apart from the things mentioned in that site, I need to filter out the message from the inbound queue based on a dynamic Id.

Following are my mule flows:

<flow name="serverFlow" >
    <jms:inbound-endpoint doc:name="REQUEST" queue="REQUEST.QUEUE" connector-ref="jmsConnector">
            <jms:selector expression="MULE_CORRELATION_ID='#[sessionVars.myCorrelationId]'"/>
    </jms:inbound-endpoint>     

    <set-payload value="#[payload] + Hello World from Receiver" doc:name="Set Payload" />

    <jms:outbound-endpoint doc:name="REPLY" queue="REPLY.QUEUE" connector-ref="jmsConnector" />
</flow>

 <flow name="mainFlow" >
    <http:listener config-ref="HTTP_Listener_Configuration" path="/jms" allowedMethods="GET" doc:name="HTTP"/>
    <set-session-variable variableName="myCorrelationId" value="#[System.currentTimeMillis().toString()]" doc:name="Set Correlation ID"/>       
   <set-payload value="New message sent from Mule - mainFlow at #[new Date()]" doc:name="Set Message"/>        
   <set-property propertyName="MULE_CORRELATION_ID" value="#[sessionVars.myCorrelationId]" doc:name="Property"/>  
    <request-reply doc:name="Request-Reply">
        <jms:outbound-endpoint doc:name="REQUEST" connector-ref="jmsConnector" queue="REQUEST.QUEUE"/>
        <jms:inbound-endpoint doc:name="REPLY" connector-ref="jmsConnector" queue="REPLY.QUEUE"/>
    </request-reply>        
    <logger message="Reply to sender: #[message]" level="WARN" doc:name="Logger" />
</flow>

If I try a static value like "<jms:selector expression="MULE_CORRELATION_ID='12345'"/>", it works. But if I try a dynamic ID using MEL, its not working. The MEL inside the jms selector expression is not working. The message stays at the queue as Unread. I used logs to see what the MULE_CORRELATION_ID is while being set at mainFlow and found the same value is set in the message that is UNREAD in the queue. So, I guess nothing is wrong in the way the MULE_CORRELATION_ID is set. The only problem is that MEL is not working within jms:selector.

Could you please help how to get MEL working within JMS selector?

Thank you very much.

2
I am able to replicate the issue with the provided XML. Seems to be bug as we able to print the values in loggers and its not working in JMS selector only(where as its working with static value as you said). I tried with <jms:selector expression="MULE_CORRELATION_ID=#[message.inboundProperties['JMSCorrelationID']]" /> but no luck.RamakrishnaN

2 Answers

3
votes

MEL is working fine in the selector but its usage is very limited. When the JMS selector is created, there's no in-flight event available to Mule so none of the event-bound data (including session) is available.

To select a very particular message, you need to use a JMS message requester, constructed with the desired selector, like:

jms://REQUEST.QUEUE?selector=MULE_CORRELATION_ID%3D'#[sessionVars.myCorrelationId]'
1
votes

Here is the working solution based on David's suggestion. I am using wmq here (not jms).

<mulerequester:config name="Mule_Requester" doc:name="Mule Requester"/>

<flow name="mainFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/test" allowedMethods="GET" doc:name="HTTP"/>        
    <set-payload value="My Message" doc:name="Set Message"/>  
    <set-property propertyName="JMSCorrelationID" value="12345" doc:name="Property"/>
    <set-session-variable variableName="myCorrelationId" value="ID:313233343500000000000000000000000000000000000000" doc:name="Set Correlation ID"/>
    <!--313233343500000000000000000000000000000000000000 is the MQMD CorrelationId for 12345. This is set by IBM MQ   -->
    <logger message="The Message to REQUEST QUEUE: #[message]" level="WARN" doc:name="Logger"/>        
    <wmq:outbound-endpoint  queue="REQUEST.QUEUE" connector-ref="wmqConnector" doc:name="OUT"/>
    <mulerequester:request config-ref="Mule_Requester" resource="wmq://REPLY.QUEUE?selector=JMSCorrelationID%3D'#[sessionVars.myCorrelationId]'" doc:name="Mule Requester" timeout="120000"/>   
    <logger message="Final Response: #[message]" level="WARN" doc:name="Logger"/>         
</flow> 

Please note, I manually moved the message from Request queue to Reply queue using MQVE for my testing. In real time, it will be done by another program.