问题
I want to iterate over all the values of the objectstore entries and log them in a mule flow. I am trying to do something like this -- is this correct or there is something better. I don't want to use java.
<objectstore:allkeys config-ref="ObjectStore" targetProperty="PropertyKey" targetScope="SESSION"/>
<foreach collection="#[PropertyKey]" doc:name="Splitting Locations_XML into chunks">
<logger message="Key--#[payload]" level="INFO" doc:name="Logger"/>
<objectstore:retrieve key="#[payload]" config-ref="ObjectStore" targetProperty="PropertyValue" targetScope="SESSION"/>
<logger message="Value--#[payload]" level="INFO" doc:name="Logger"/>
</foreach>
回答1:
I would argue that you are trying to shoe horn essentially procedural code into a pipes and filters pattern use flow processors for use cases which naturally call out for pipes and filters and encapsulate procedural logic within components and then include the component within the flow. Avoid writing procedural logic using Mule constructs. I know like most design issues there is some grey area but in most cases a best practice can be agreed upon.
From a purely implementation view point this does look valid.
来源:https://stackoverflow.com/questions/31752528/how-to-loop-over-the-keys-values-of-a-objectstore-in-mule-flow