具有请求 - 响应交换模式的Mule自定义聚合器

时间:2012-11-06 15:53:03

标签: mule

我正在尝试向使用<recipient-list>和自定义聚合器的入站http端点发出请求以组合多个结果。如何让我的入站http端点“等待”自定义聚合器的结果?

以下是我的样本流程。聚合器完美运行。但由于是异步的,因此入站http端点立即返回。我真正想做的是从Custom Aggregator返回结果作为对http端点的响应。我觉得我错过了一些简单的事情。

<flow name="AggregationExample">
    <http:inbound-endpoint
        exchange-pattern="request-response"
        host="localhost"
        port="8082"
        path="test/aggregate"
        />  

    <recipient-list evaluator="groovy" expression="['vm://source1','vm://source2']"></recipient-list>

        <!-- How do I wait for result of custom aggregator? -->
</flow>

<flow name="SourceAggregation">
    <vm:inbound-endpoint path="sourceresult" />

    <custom-aggregator failOnTimeout="true" class="com.example.MySourceAggregator"/>

    <logger message="RESULTS: #[payload]"/>
</flow>

<flow name="Source1">
    <vm:inbound-endpoint path="source1" />

    <set-payload value="#[groovy:Thread.currentThread().getContextClassLoader().getResourceAsStream('example-source1.json').text]"/>

    <vm:outbound-endpoint path="sourceresult" />
</flow>

<flow name="Source2">
    <vm:inbound-endpoint path="source2" />

    <set-payload value="#[groovy:Thread.currentThread().getContextClassLoader().getResourceAsStream('example-source2.json').text]"/>

    <vm:outbound-endpoint path="sourceresult" />
</flow>

1 个答案:

答案 0 :(得分:1)

request-reply流程中使用AggregationExample路由器而不是收件人列表:调度到另一个发送到Source1Source2的流。

一般来说,我不确定你想要实现的目标:你是否建立这个装置只是为了并行读取两个文件?或者还有更多吗?如果只是为了那个,你确定它真的值得:并发文件读取没有任何物理限制吗?如果全部用于优化,则缓存可能是更好的路径。

另外,如果recipient-list中的收件人是静态的,为什么要使用此路由器而不是all路由器?

最后,您是否在使用Groovy表达式来读取文件时遇到问题?