我是 Mule 新手,正在解决一个问题,该问题需要一个流程,将消息发送到 Mule 消息总线,监听器可以接收该流程,以便在工作人员完成时接收成功处理这些消息的通知。主要标准是“调度程序流”不会被阻止继续执行其工作(将其他不同的消息放置在总线上以供潜在的其他监听器使用)。
我有一个测试应用程序,一直在 MuleStudio 中运行(如下),它封装了我想要实现的基础知识,并进行了简化;这是一个非常简单的 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>
最佳答案
您可以使用延续来实现您想要的目的。我写了一个blog post关于这个话题。
关于asynchronous - 骡子3 : async reply w/reply on different main flow thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10746935/