【问题标题】:Mule 3 : async reply w/ reply on different main flow threadMule 3:异步回复,在不同的主流线程上回复
【发布时间】:2012-05-25 00:09:37
【问题描述】:

我是 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>    

【问题讨论】:

  • 好的,在阅读更多主题并在论坛上找到一些来自 David Dossot 的非常相关的电子邮件主题后,在这里回答我自己的问题;完成这项工作的一种方法是将请求-回复推送到私有流程中;私有流在它们自己的线程中运行,并且处理可以在引用流中继续(在我的例子中是“主”)。 需要围绕私有线程的引用来强制它是异步的。这是上面的相关代码更改:
  • .... ....
  • 很高兴能够间接帮助您:) 那么这个问题的状态如何?解决了吗?如果没有,你能用最新的配置和当前的问题更新它吗?

标签: asynchronous nonblocking mule


【解决方案1】:

您可以使用延续来实现您想要的。我已经写了一个关于这个话题的blog post

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 2022-12-05
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    相关资源
    最近更新 更多