在foreach里面的骡子变压器

时间:2015-03-18 16:43:38

标签: mule

我使用的是Mule 3.5。 我在foreach标签中使用bean-builder-transformer时遇到了问题。 这是我的第一次测试:

<flow name="mule.activity">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10000"/>
<db:select config-ref="JSDB" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT * FROM ACTIVITY WHERE rownum <= 6]]></db:parameterized-query>
</db:select>
</poll>
<foreach doc:name="For Each">
<logger message="start id #[payload.'ID']" level="DEBUG" category="mule.activity" doc:name="log" />
</foreach>

这是日志:

[2015-03-18 16:29:23,165] DEBUG: start id 1363230
[2015-03-18 16:29:23,165] DEBUG: start id 1363231
[2015-03-18 16:29:23,165] DEBUG: start id 1363232
[2015-03-18 16:29:23,165] DEBUG: start id 1363233
[2015-03-18 16:29:23,166] DEBUG: start id 1363236
[2015-03-18 16:29:23,166] DEBUG: start id 1363237

所以一切都好。

现在我在foreach标签中添加了一个bean-builder-transformer:

<foreach doc:name="For Each">

<logger message="start payload: #[payload]" level="DEBUG" category="mule.activity" doc:name="log" />
<logger message="start id #[payload.'ID']" level="DEBUG" category="mule.activity" doc:name="log" />

<bean-builder-transformer beanClass="com.jsolutions.mule.IO">
<bean-property property-name="bean_prop_1" evaluator="map-payload" expression="TABLE_FIELD_1" optional="true" />
<bean-property property-name="bean_prop_2" evaluator="map-payload" expression="TABLE_FIELD_2" optional="true" />
... (map all query fields except ID)
</bean-builder-transformer>

<logger message="end payload: #[payload]" level="DEBUG" category="mule.activity" doc:name="log" />
<logger
message="end id #[payload.'ID']" level="DEBUG" category="mule.activity" doc:name="log" />

<!-- use the message in order to call a ws service -->
</foreach>

这是日志:

[2015-03-19 10:08:28,668] DEBUG: start payload: {FIELD_1=004369951, ID=1363230}
[2015-03-19 10:08:28,676] DEBUG: start id 1363230
[2015-03-19 10:08:28,684] DEBUG: end payload: com.jsolutions.mule.IO@67231ee8
[2015-03-19 10:08:28,687] DEBUG: end id null
[2015-03-19 10:08:28,688] DEBUG: start payload: {FIELD_1=004369951, ID=1363231}
[2015-03-19 10:08:28,688] DEBUG: start id null
[2015-03-19 10:08:28,690] DEBUG: end payload: com.jsolutions.mule.IO@2bc6e9f1
[2015-03-19 10:08:28,690] DEBUG: end id null
[2015-03-19 10:08:28,691] DEBUG: start payload: {FIELD_1=004369951, ID=1363232}
[2015-03-19 10:08:28,691] DEBUG: start id null
[2015-03-19 10:08:28,692] DEBUG: end payload: com.jsolutions.mule.IO@1028e3ab
[2015-03-19 10:08:28,692] DEBUG: end id null
[2015-03-19 10:08:28,693] DEBUG: start payload: {FIELD_1=TO3925878, ID=1363233}
[2015-03-19 10:08:28,693] DEBUG: start id null
[2015-03-19 10:08:28,694] DEBUG: end payload: com.jsolutions.mule.IO@6c7af7d6
[2015-03-19 10:08:28,695] DEBUG: end id null
[2015-03-19 10:08:28,695] DEBUG: start payload: {FIELD_1=TS7066322, ID=1363236}
[2015-03-19 10:08:28,695] DEBUG: start id null
[2015-03-19 10:08:28,697] DEBUG: end payload: com.jsolutions.mule.IO@7d253a3d
[2015-03-19 10:08:28,697] DEBUG: end id null
[2015-03-19 10:08:28,698] DEBUG: start payload: {FIELD_1=022245675, ID=1363237}
[2015-03-19 10:08:28,698] DEBUG: start id null
[2015-03-19 10:08:28,699] DEBUG: end payload: com.jsolutions.mule.IO@1712bafb
[2015-03-19 10:08:28,700] DEBUG: end id null

我不明白为什么在第一次迭代之后,id总是&#34; null&#34; ... 提前感谢您的回复。

1 个答案:

答案 0 :(得分:1)

假设启动有效负载是一个映射(这仍然是基于问题下的注释的TBD),请使用以下表达式来检索ID:

#[message.payload.ID]

事实上,虽然在大多数情况下直接使用payload访问消息有效负载,但在没有情况下会出现模糊的情况。使用message.payload始终有效。