質問

EDIT: Simplified question.

Why on earth, the file written is garbage (binary serilized data) instead of the payload that was set in the Groovy component? This only happens if there is an "All" Flow component.

Flow:

enter image description here

XML:

<file:connector name="OutputFile" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" writeToDirectory="#{systemProperties['user.home']}"/>
<flow name="AllProblemFlow1" doc:name="AllProblemFlow1">
    <vm:inbound-endpoint exchange-pattern="one-way" path="in" doc:name="VM"/>
    <all doc:name="All">
        <processor-chain>
            <scripting:component doc:name="Groovy">
                <scripting:script engine="Groovy">
                    <scripting:text><![CDATA[return payload + 1]]></scripting:text>
                </scripting:script>
            </scripting:component>
        </processor-chain>
        <processor-chain>
            <scripting:component doc:name="Groovy">
                <scripting:script engine="Groovy">
                    <scripting:text><![CDATA[return payload + 2]]></scripting:text>
                </scripting:script>
            </scripting:component>
        </processor-chain>
    </all>
    <logger message="All payload: #[payload]" level="INFO" doc:name="Logger"/>
    <scripting:component doc:name="Groovy">
        <scripting:script engine="Groovy">
            <scripting:text><![CDATA[return "new payload"]]></scripting:text>
        </scripting:script>
    </scripting:component>
    <file:outbound-endpoint responseTimeout="10000" connector-ref="OutputFile" doc:name="File" outputPattern="output.txt" path="#{systemProperties['user.home']}"/>
</flow>
役に立ちましたか?

解決

This is very tricky: the all message processor changes the very nature of the in-flight Mule message from a MuleMessage to a MuleMessageCollection. Changing the payload on a MuleMessageCollection is basically ineffective.

You need to forcefully replace the current MuleMessageCollection with a brand new MuleMessage. Use the following code for your last Groovy component:

<scripting:text><![CDATA[
    return new org.mule.DefaultMuleMessage("new payload", muleContext)
]]></scripting:text>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top