我想迭代一个数组,并使用从数组中获取的值将其放入http入站端点。我如何能够遍历此数组并从数组中获取值以将其作为变量置于http入站端点中?
我以前尝试的代码是:
<flow name="foreachFlow1" doc:name="foreachFlow1">
<poll frequency="2000">
<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>
</poll>
</flow>
我收到了错误
Invalid content was found starting with element 'poll'
答案 0 :(得分:4)
入站端点是消息源,无法按照您描述的方式进行参数化。
要实现您的目标,请尝试使用<poll>
消息来包裹foreach
使用http:outbound-endpoint
执行GET
(@method)request-response
的{{1}}(@交换 - 交流。互动。
诀窍是通过foreach
将HTTP调用的结果带回来,默认情况下不会这样做。以下说明了一种潜在的方法:
<flow name="foreachFlow1">
<poll frequency="2000">
<processor-chain>
<set-variable variableName="httpResponses" value="#[[]]" />
<foreach collection="#[groovy:['localhost:8082', 'localhost:8083']]">
<http:outbound-endpoint
exchange-pattern="request-response" address="http://#[payload]"
method="GET" />
<expression-component>httpResponses.add(message.payloadAs(java.lang.String))
</expression-component>
</foreach>
</processor-chain>
</poll>
<logger level="INFO" message="#[httpResponses]" />
</flow>
<!-- Test server stubs -->
<flow name="server8082">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8082" />
<set-payload value="This is 8082" />
</flow>
<flow name="server8083">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8083" />
<set-payload value="This is 8083" />
</flow>