如何进行并行出站呼叫 [英] How to make parallel outbound calls

查看:159
本文介绍了如何进行并行出站呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例需要使用smne数据丰富我的输入并将其发送到出站端点。

My use case requires to enrich my input with smne data and send it to an outbound endpoint.

通过调用两个Web服务然后从回复中提取数据来获取用于丰富的数据。
这个提取的数据被丰富到我的输入XML中并发送到出站端点。

The data for enriching is obtained by making calls to two web-services and then extract the data from the reply. This extracted data is enriched into my input XML and sent to an outbound endpoint.

我需要进行的两个Web服务调用需要并行因为他们没有依赖他人。这样我就可以节省我的处理时间。

The two web-service calls that I need to make needs to be parallel, as they don't have dependency on another. This way I could save my processing time.

请建议我如何在Mule的流程中实现这种并行处理。

Please suggest how I could achieve this parallel processing in a flow in Mule.

注意:我尝试过使用ALL流控制,但似乎是按顺序调用Web服务(子流)。

Note: I have tried using ALL flow control, but it seems that is calling the web-services (sub-flows) sequentially.

以下是我的抽象流程。

<flow name="mainFlow">
    <inbound-endpoint> .....

    <some validation>

    <setting some flow variables>

    <!-- Now make calls to the sub-flows which has some processing of the input and make some web-service calls -->
    <all>
        <flow-ref name="myFlow1" />
        <flow-ref name="myFlow2" />
        <flow-ref name="myFlow3" />
    </all>

    <enrich the input with the data obtained from the output of the above three flows>

    <outbound-endpoint>
</flow>



<flow name="myFlow1">
    <some transformer to transform the payload provided >

    < the tran sformed payload is passed as input to the web-service call>

    <http:outbound-endpoint ...>

    <transform the reply from the web-service call>
</flow>



<flow name="myFlow2">
    <some transformer to transform the payload provided >

    < the tran sformed payload is passed as input to the web-service call>

    <http:outbound-endpoint ...>

    <transform the reply from the web-service call>
</flow>



<flow name="myFlow3">
    <some transformer to transform the payload provided to it>

    < the tran sformed payload is passed as input to the web-service call>

    <http:outbound-endpoint ...>

    <transform the reply from the web-service call>
</flow>


推荐答案

这是一个简单的配置,显示了一种制作方法带有两个HTTP出站端点的fork / join。要添加第三个端点,请将 MULE_CORRELATION_GROUP_SIZE 设置为 3 MULE_CORRELATION_SEQUENCE 第三个 async flow-ref 3

Here is a simple configuration that shows one way to make a fork/join with two HTTP outbound endpoints. To add a third endpoint, set MULE_CORRELATION_GROUP_SIZE to 3 and the MULE_CORRELATION_SEQUENCE of the third async flow-ref to 3.

<flow name="fork">
    <vm:inbound-endpoint path="fork.in" />
    <set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
        value="2" />
    <all enableCorrelation="IF_NOT_SET">
        <async>
            <set-property propertyName="MULE_CORRELATION_SEQUENCE"
                value="1" />
            <flow-ref name="parallel1" />
        </async>
        <async>
            <set-property propertyName="MULE_CORRELATION_SEQUENCE"
                value="2" />
            <flow-ref name="parallel2" />
        </async>
    </all>
</flow>

<sub-flow name="parallel1">
    <logger level="INFO" message="parallel1: processing started" />
    <http:outbound-endpoint address="..."
        exchange-pattern="request-response" />
    <logger level="INFO" message="parallel1: processing finished" />
    <flow-ref name="join" />
</sub-flow>

<sub-flow name="parallel2">
    <logger level="INFO" message="parallel2: processing started" />
    <http:outbound-endpoint address="..."
        exchange-pattern="request-response" />
    <logger level="INFO" message="parallel2: processing finished" />
    <flow-ref name="join" />
</sub-flow>

<sub-flow name="join">
    <collection-aggregator timeout="6000"
        failOnTimeout="true" />
    <combine-collections-transformer />
    <logger level="INFO"
        message="Continuing processing of: #[message.payloadAs(java.lang.String)]" />
</sub-flow>

编辑:在上面的配置中,聚合器在6秒后超时。这可能对您的实际用例来说太短了:根据您的需要增加。此外,它设置为超时失败,这可能不是您希望的行为,以防所有出站HTTP端点交互都没有成功:由您根据您的用例决定。

In the above config, the aggregator times out after 6 seconds. This is potentially too short for your actual use case: increase as you see fit. Also it is set to fail on time-out, which is maybe not the behaviour you desire in case not all the outbound HTTP endpoint interactions succeeded: it's up to you to decide based on your use case.

这篇关于如何进行并行出站呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆