2

Mule 3.3.0
我有一个拆分有效负载的流程。
然后每个项目都会通过一个自定义转换器,如果项目格式错误,它可能会抛出异常。
我有一个捕获异常策略来将错误项记录到文件中。
我希望流程继续处理其余项目,据我所知,这应该是预期的行为。
问题是流量停止了。

我附上了一个简单的测试流程和一个简单的测试文件。该文件是一个 csv 文件,有 2 行,每行有 3 个字段。我使用 groovy 脚本,首先将文件拆分为行,然后将每行拆分为字段。当字段格式错误时,我还使用 groovy 脚本来模拟异常。在这种情况下,如果字段是单词“goodbye”,它将抛出 RuntimeException。如果您测试此流程,您将看到异常后的其余字段不会得到处理(即在这种情况下记录)。在这个特殊的例子中,捕获异常策略甚至不会触发。

输入文件:

你好,残酷,世界
再见,残酷,世界

测试流

测试流

测试用例.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>
4

1 回答 1

4

我首先要做的是分离你的主要流程。每次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>
于 2012-09-26T21:47:56.260 回答