Mule 3 : async reply w/ reply on different main flow thread

I'm new to Mule, and am working on a problem that requires a flow that diapatches messages to a Mule message bus that listeners can receive to also receive notification of successful processing of those messages when the workers are done. The main criteria is that the 'dispatcher flow' not be blocked from continuing to do its work (of placing other different messages on the bus for potentially other listeners).

I have a test app that I've been running in MuleStudio (below) that encapsultates the basics of what I'm trying to achieve, simplified; this is a very simple 2 flow app, using request-reply to allow the 2nd flow to send a reply back to the main flow; the main issue here is that the main flow's thread is blocked, preventing it from doing anything until the response comes back. Is there a way to have the response come back on a different thread of the main flow, or are there other ways of accomplishing this given the criteria ?

Thanks for any help or pointers ;-)

...

<!-- simple Groovy transformer that changes the msg payload to a greeting w/ the current time-->
<scripting:transformer name="toCurrentTime">
    <scripting:script engine="groovy">
        import java.text.SimpleDateFormat;

        def DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";    
        def cal = Calendar.getInstance();
        def sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return "Response @ time " + sdf.format(cal.getTime())

    </scripting:script>    
</scripting:transformer>


<!-- 
    note : neither of the following are allowed on the flow b/c of the request-reply    
    processingStrategy="synchronous"
    processingStrategy="queued-asynchronous"
-->

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

    <http:inbound-endpoint ref="httpEventInjector" doc:name="HTTP"/>

    <logger message="starting main flow" level="INFO"/>

    <request-reply storePrefix="mainFlow">  
        <vm:outbound-endpoint path="worker"></vm:outbound-endpoint>
        <vm:inbound-endpoint path="reply"></vm:inbound-endpoint> 
    </request-reply>


    <!--  processing continues once we get the response on the 'reply' channel above from the worker -->    
    <!--  generate the response for the browser -->    
    <logger message="finishing main flow w/ browser response" level="INFO"/>        
    <response>
        <transformer ref="toCurrentTime"/>
    </response>
</flow>


<flow name="worker" doc:name="worker">      
    <vm:inbound-endpoint path="worker"/>

    <logger message="starting worker task(s) ...." level="INFO"/>

    <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"/>
</flow>    


You can use continuations to achieve what you want. I've written a blog post about this topic.

链接地址: http://www.djcxy.com/p/52520.html

上一篇: 在node.js中出现奇怪的行为

下一篇: Mule 3:在不同主流线程上的异步回复