I am trying to poll several addresses (URL links) from a list that contains all these addresses using the http polling connector in Mule. Currently, I am only able to poll from one address but I would like to find a way to use this list to iterate the polling for each site. Is there anything built within Mule that provides such function?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Is composite source what you're looking for? It allows you to have more than one endpoint in the inbound.
e.g. from 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>
....
Edit:
The following is a simple foreach example:
<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>
Basically, the 'tricky' part is to figure out that the payload becomes the current item in the collection you're iterating over (the docs do a wonderful job at pointing that out... well at least if you're into fishing :P).