2

我是 Mule 的新手,并且正在解决一个问题,该问题需要一个将消息分发到 Mule 消息总线的流,侦听器可以接收该流,以便在工作人员完成时接收成功处理这些消息的通知。主要标准是“调度程序流”不会被阻止继续执行其工作(将其他不同的消息放置在总线上以供潜在的其他侦听器使用)。

我有一个测试应用程序,我一直在 MuleStudio(如下)中运行,它封装了我想要实现的基础知识,简化了;这是一个非常简单的 2 流应用程序,使用 request-reply 允许第 2 流向主流发送回复;这里的主要问题是主流的线程被阻塞,阻止它做任何事情,直到响应返回。有没有办法让响应在主流程的不同线程上返回,或者在给定标准的情况下有其他方法可以实现吗?

感谢您的任何帮助或指点;-)

...

<!-- 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>    

4

1 回答 1

2

您可以使用延续来实现您想要的。我写了一篇关于这个主题的博客文章。

于 2014-01-07T20:49:13.113 回答