【问题标题】:Is there a way to poll several addresses using Mule's HttpPollingConnector?有没有办法使用 Mule 的 HttpPollingConnector 轮询多个地址?
【发布时间】:2013-09-29 00:18:52
【问题描述】:

我正在尝试使用 Mule 中的 http 轮询连接器从包含所有这些地址的列表中轮询多个地址(URL 链接)。目前,我只能从一个地址进行轮询,但我想找到一种方法来使用此列表来迭代每个站点的轮询。 Mule 中是否有内置的东西可以提供这样的功能?

【问题讨论】:

    标签: http mule polling mule-studio


    【解决方案1】:

    您正在寻找复合源吗?它允许您在入站中拥有多个端点。

    例如来自http://www.mulesoft.org/documentation-3.2/display/32X/Bookstore+Example

    <flow name="CatalogService">
        <composite-source>
            <!-- Public interface -->
            <inbound-endpoint address="http://0.0.0.0:8777/services/catalog" exchange-pattern="request-response">
                <cxf:jaxws-service serviceClass="org.mule.example.bookstore.CatalogService" />
            </inbound-endpoint>
    
            <!-- Administration interface -->
            <inbound-endpoint address="servlet://catalog" exchange-pattern="request-response">
                <!-- Convert request parameters to Book object -->
                <custom-transformer class="org.mule.example.bookstore.transformers.HttpRequestToBook" />
                <response>
                    <!-- Format response to be a nice HTML page -->
                    <custom-transformer class="org.mule.example.bookstore.transformers.AddBookResponse" />
                    <!-- Force text/html, otherwise it falls back to request 
                        props, which have form-encoded one -->
                    <transformer ref="setHtmlContentType" />
                </response>
            </inbound-endpoint>
        </composite-source>
        ....
    

    编辑:

    下面是一个简单的foreach例子:

    <flow name="foreachFlow1" doc:name="foreachFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <foreach collection="#[groovy:['localhost:8082', 'localhost:8083']]" doc:name="For Each">
            <http:outbound-endpoint exchange-pattern="request-response" address="http://#[payload]" method="GET" doc:name="HTTP"/>
        </foreach>
    </flow>
    <flow name="foreachFlow2" doc:name="foreachFlow2">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
        <logger message="in flow2" level="INFO"/>
    </flow>
    <flow name="foreachFlow3" doc:name="foreachFlow3">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"/>
        <logger message="in flow3" level="INFO"/>
    </flow>
    

    基本上,“棘手”的部分是找出有效负载成为您正在迭代的集合中的当前项目(文档在指出这一点方面做得很好......至少如果你是钓鱼:P)。

    【讨论】:

    • 不完全是,我希望能够将所有地址放入入站的数组或列表中。有没有办法在 Mule 中做到这一点?
    • 我不认为你可以。 Mule 是基于 Spring 构建的……入站中的地址属性使用 setter 方法映射到 Java 属性集。如果“地址”属性是字符串,则不能设置列表或数组。
    • 我明白了。那么是否有另一种方法,例如将列表或数组放在其他地方并迭代使用相同的入站端点?我正在尝试这样做,因为执行我之前提到的操作比让不同的入站端点执行相同的轮询请求但使用不同的 http 地址更优化。
    • 好吧..我又读了一遍,似乎我误解了你想要做什么。如果轮询不需要入站,则需要出站 http 消息处理器。那么不需要复合源......这只是使用Mule的foreach遍历您的地址列表并在每个地址上轮询(http:outbound)的问题。
    • 您能否给我一些指导,让我知道如何解决这个问题?就像我如何能够迭代地浏览我的列表和投票一样?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多