首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mule 3:异步回复,在不同的主流线程上回复

Mule 3:异步回复,在不同的主流线程上回复
EN

Stack Overflow用户
提问于 2012-05-25 08:09:37
回答 1查看 1.3K关注 0票数 2

我是Mule的新手,我正在处理一个问题,这个问题需要一个流将消息传递到Mule消息总线,侦听器可以接收该总线,以便在工作进程完成时也能接收到成功处理这些消息的通知。主要的标准是不阻止'dispatcher flow‘继续它的工作(将其他不同的消息放在总线上,用于潜在的其他侦听器)。

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

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

..。

代码语言:javascript
复制
<!-- 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>    

EN

回答 1

Stack Overflow用户

发布于 2014-01-08 04:49:13

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10746935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档