Mule: JMS reply queue consumes all the messages. I want to process messages that coming to reply queue

廉价感情. 提交于 2019-12-12 04:39:21

问题


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?


回答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 ..




回答2:


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.



来源:https://stackoverflow.com/questions/25394528/mule-jms-reply-queue-consumes-all-the-messages-i-want-to-process-messages-that

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!