0

I've a Mule(3.5) flow with JMS request-reply block. I saw that all the messages coming to reply queue get consumed automatically. I would like to process messages that come to jms reply queue. I've tried with jms:selector and jms requester module so far but no luck. Is there any way to achieve this?

Code:

<mule>
<flow name="main" doc:name="main">

        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" path="test" port="2000" doc:name="HTTP"/>

        <logger message="starting main flow" level="INFO" doc:name="Logger"/>

        <request-reply storePrefix="mainFlow">  
            <jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ1"  exchange-pattern="one-way"/>
            <jms:inbound-endpoint queue="StudioOUT" connector-ref="Active_MQ1" exchange-pattern="one-way">
                <property key="selector" value="JMSCorrelationID='#[message.correlationId]'"/>
            </jms:inbound-endpoint> 
        </request-reply>
    </flow>

    <flow name="worker" doc:name="worker">
                <jms:inbound-endpoint queue="StudioIN" connector-ref="Active_MQ1" doc:name="JMS"/>
            <async doc:name="Async">
                <logger message="starting worker task(s) .... Payload: #[payload], Request: #[message.inboundProperties['http.request']]" level="INFO" doc:name="Logger"/>

                <scripting:component doc:name="thread-sleep(10s)">
                    <scripting:script engine="Groovy">
                        System.out.println "about to sleep @ time" + System.currentTimeMillis()
                        Thread.sleep(10000);
                        System.out.println "done sleeping @ time" + System.currentTimeMillis()
                    </scripting:script>
                </scripting:component>
                <logger message="finishing up worker task(s) ...." level="INFO" doc:name="Logger"/>
            </async>
    </flow> 

</mule>

I would like to process whatever comes to reply queue StudioOUT. Is there any proper way to achieve this?

Neel
  • 303
  • 1
  • 4
  • 15

2 Answers2

1

First remove <property key="selector" value="JMSCorrelationID='#[message.correlationId]'"/> in Inbound JMS endpoint

Then Try the following to consume message based on filter in Inbound JMS endpoint :-

<jms:inbound-endpoint queue="StudioOUT" connector-ref="Active_MQ1" exchange-pattern="one-way">
 <jms:selector expression="JMSCorrelationID= #[message.correlationId]" /> 

</jms:inbound-endpoint> 

and to if you want to set a property to message and send to a Outbound JMSQueue in Outbound JMS endpoint try the following:

  <jms:outbound-endpoint queue="StudioOUT" connector-ref="Active_MQ" doc:name="JMS">
         <jms:object-to-jmsmessage-transformer name="ObjectToJmsMessage" />

            <message-properties-transformer>
            <add-message-property key="CorrelationID" value="#[message.correlationId]"/> 
            </message-properties-transformer>
   </jms:outbound-endpoint>

UPDATED FLOW:- To select a JMS message for a particular type we need to set it in the queue first ... For example let's assume we need to select and consume only those JMS message that has priority 7 .. Now lets's send messages to JMS queue with priority as 7 ..

So set the following in your JMS outbound endpoint

<jms:outbound-endpoint queue="StudioOUT" connector-ref="Active_MQ" doc:name="JMS">
   <jms:object-to-jmsmessage-transformer name="ObjectToJmsMessage" />
         <message-properties-transformer>
           <add-message-property key="Priority" value="7"/> 
    </message-properties-transformer>
</jms:outbound-endpoint>

Now this will send messages to Queue with JMS priority as 7 ..

Now you can consume these messages from queue whose JMS proirity is 7 .. remaing message will be ignored and will not be consumed .. So, Now use the following in your JMS inbound endpoint to filter the messages :-

<jms:inbound-endpoint queue="StudioOUT" connector-ref="Active_MQ1" exchange-pattern="one-way">
<jms:selector expression="JMSPriority = 7" /> 
</jms:inbound-endpoint> 

Here only messages will be consumed which has priority as 7 .. Now you can configure your inbound to select a particular type of messages from queue .. but make sure that, messages of that particular type (here messages with priority=7) exists in JMS queue .. So .. for that purpose you need to send few messages to JMS queue using JMS Outbound endpoint which I showed you now ..

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
  • Thanks for the reply. I've tried this option too. I've added into my , it compiles and runs fine but as soon as reply queue StudioOUT receive the reply it consumes automatically. I would like to stop it consumes automatically because I want to process those messages by storing in file or by redirecting somewhere. How can I consume messages from reply queue StudioOUT? – Neel Aug 20 '14 at 17:54
  • You can filter the message not by correlationId then .. You need to filter using JMS priority ... and then you need to read the value of priority by reading from a file – Anirban Sen Chowdhary Aug 20 '14 at 18:03
0

Use the following to copy the Correlation ID when sending message onto JMS outbound

<jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ1"  exchange-pattern="one-way">            
    <copy-properties propertyName="*"></copy-properties>
<jms:outbound-endpoint> 

Hope this helps.

user1760178
  • 6,277
  • 5
  • 27
  • 57
  • Thanks for reply, I've added in my but it didn't help. As soon as reply queue StudioOUT receive the reply it consumes automatically. – Neel Aug 20 '14 at 17:51