骡子3.3.0
我有一个分割有效负载的流程。
然后每个项目都会经过一个自定义转换器,如果项目格式错误,则可能会引发异常。
我有一个捕获异常策略来将错误项记录到文件中。
我希望流程继续处理其余项目,据我所知,这应该是预期的行为。
问题是流程停止了。
我附上了一个简单的测试流程和一个简单的测试文件。 该文件是一个 csv 文件,有 2 行,每行有 3 个字段。 我使用 groovy 脚本,首先将文件拆分为行,然后将每行拆分为字段。 我还使用 Groovy 脚本来模拟字段格式错误时的异常。在这种情况下,如果该字段是单词“再见”,它将抛出 RuntimeException。 如果您测试此流程,您将看到异常后的其余字段将不会得到处理(即在本例中记录)。 在这个特定的示例中,捕获异常策略甚至不会触发。
输入文件:
hello,cruel,world goodbye,cruel,world
TestFlow
TestCase.mflow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd ">
<file:connector name="inputFileConnector" autoDelete="true"
streaming="false" validateConnections="true" doc:name="File" fileAge="60000"
readFromDirectory="#{systemProperties['user.home']}"/>
<catch-exception-strategy name="Catch_Exception_Strategy">
<logger message="!!!!! Exception Handler !!!!!" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<flow name="TestCaseFlow1" doc:name="TestCaseFlow1">
<file:inbound-endpoint path="#{systemProperties['user.home']}"
responseTimeout="10000" doc:name="Input File" fileAge="100" connector-ref="inputFileConnector">
<file:filename-regex-filter pattern="input.csv"
caseSensitive="false" />
</file:inbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split('\n');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split(',');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[if (payload.equals('goodbye')) {
throw new java.lang.RuntimeException('Dang!');
}
return payload]]></scripting:text>
</scripting:script>
</scripting:component>
<logger message=">>>>>>>>>>>>>>>>>> #[payload]" level="INFO" doc:name="Logger" />
</flow>
</mule>
最佳答案
我首先要做的就是分离你的主要流程。在每个collection-splitter
放置一个JMS或VMoutbound-endpoint
之后,这样每条消息都将拥有自己的线程,如果一个失败,其他消息将不会受到影响。
<flow name="flow1">
<file:inbound-endpoint path="#{systemProperties['user.home']}"
responseTimeout="10000" doc:name="Input File" fileAge="100" connector-ref="inputFileConnector">
<file:filename-regex-filter pattern="input.csv"
caseSensitive="false" />
</file:inbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split('\n');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter"/>
<vm:outbound-endpoint path="toFlow2"/>
</flow>
<flow name="flow2">
<vm:inbound-endpoint path="toFlow2"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split(',');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter"/>
<vm:outbound-endpoint path="toFlow3"/>
</flow>
<flow name="flow3">
<vm:inbound-endpoint path="toFlow3"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[if (payload.equals('goodbye')) {
throw new java.lang.RuntimeException('Dang!');
}
return payload]]></scripting:text>
</scripting:script>
</scripting:component>
<logger message=">>>>>>>>>>>>>>>>>> #[payload]" level="INFO" doc:name="Logger" />
</flow>
关于exception - 即使在异常之后也继续 Mule (3.3) 流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12606980/