Mule分散 - 聚集路由器抛出异常

时间:2014-08-17 13:05:16

标签: mule mule-studio

我正在探索Mule scatter-gather,以便在Mule fork和join 模式中并行处理流。我的Mule配置如下:

 <flow name="fork" doc:name="fork">
    <http:inbound-endpoint host="localhost" port="8090" path="mainPath" exchange-pattern="request-response" doc:name="HTTP"/>
    <set-property propertyName="MULE_CORRELATION_GROUP_SIZE"  value="2" doc:name="Property"/>
     <!--  <all enableCorrelation="IF_NOT_SET" doc:name="All"> -->
            <scatter-gather timeout="6000">
              <processor-chain>
               <async doc:name="Async">
               <set-property propertyName="MULE_CORRELATION_SEQUENCE" value="1" doc:name="Property"/>
               <flow-ref name="Flow1" doc:name="Flow Reference"/>
               </async>
              </processor-chain>

              <async doc:name="Async">
              <set-property propertyName="MULE_CORRELATION_SEQUENCE" value="2" doc:name="Property"/>
              <flow-ref name="Flow2" doc:name="Flow Reference"/>
               </async>
               <!-- </all> -->
               </scatter-gather>
               <logger message="Main Flow" level="INFO" doc:name="Logger"/>
    </flow>

    <sub-flow name="Flow1" doc:name="Flow1">
     <logger level="INFO" message="Flow1: processing started" doc:name="Logger"/>
     <set-payload value="Flow1 Payload" doc:name="Set Payload"/>
     <!-- Transformation payload -->
      <logger level="INFO" message="Flow1: processing finished" doc:name="Logger"/>
      <flow-ref name="Join-Flow" doc:name="Flow Reference"/>
     </sub-flow>

    <sub-flow name="Flow2" doc:name="Flow2">
    <logger level="INFO" message="Flow2: processing started" doc:name="Logger"/>
     <set-payload value="Flow2 Payload" doc:name="Set Payload"/>
     <scripting:component doc:name="Groovy">
     <scripting:script engine="Groovy"><![CDATA[sleep(2000); return message.payload;]]></scripting:script>
     </scripting:component>
      <!--  Transformation payload -->
    <logger level="INFO" message="Flow2: processing finished" doc:name="Logger"/>
     <flow-ref name="Join-Flow" doc:name="Flow Reference"/>
    </sub-flow>

    <sub-flow name="Join-Flow" doc:name="Join-Flow">
    <collection-aggregator timeout="6000" failOnTimeout="true" doc:name="Collection Aggregator"/>
    <combine-collections-transformer doc:name="Combine Collections"/>
    <logger level="INFO"  message="Combined Payload: #[message.payload]" doc:name="Logger"/>
    <set-payload value="Soap XML Response" doc:name="Set Payload"/>
    </sub-flow> 

虽然我在记录器中获得聚合的有效负载,但分散和聚集正在抛出异常:

Exception stack is:
1. null (java.lang.UnsupportedOperationException)
  org.mule.VoidMuleEvent:50 (null)
2. null (java.lang.UnsupportedOperationException). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.UnsupportedOperationException
    at org.mule.VoidMuleEvent.getMessage(VoidMuleEvent.java:50)
    at org.mule.api.routing.AggregationContext$1.evaluate(AggregationContext.java:41)
    at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:517)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

INFO  2014-08-17 18:04:52,008 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing started
INFO  2014-08-17 18:04:52,016 [[try1].fork.1.02] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing started
INFO  2014-08-17 18:04:52,017 [[try1].fork.1.02] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing finished
INFO  2014-08-17 18:04:54,309 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing finished
INFO  2014-08-17 18:04:54,347 [[try1].fork.2.02] org.mule.api.processor.LoggerMessageProcessor: Combined Payload: [Flow1 Payload, Flow2 Payload]

一个有趣的事实是,如果我使用<all>路由器而不是分散 - 聚集,我就不会得到此异常。但我想<all>路由器按顺序处理流程而不是按Mule documentation并行处理流程。因此,我尝试在所有路由器上选择分散 - 聚集。但我不知道如何处理 scatter-gather 引发的上述异常。有什么出路吗?

更新流量: -

<flow name="fork" doc:name="fork">
<http:inbound-endpoint host="localhost" port="8090" path="mainPath" exchange-pattern="request-response" doc:name="HTTP"/>


         <scatter-gather timeout="6000">
            <processor-chain>
              <flow-ref name="Flow1" doc:name="Flow Reference"/>
                 </processor-chain>
               <flow-ref name="Flow2" doc:name="Flow Reference"/>
          </scatter-gather>
            <logger message="Main Flow" level="INFO" doc:name="Logger"/>
        </flow>

        <sub-flow name="Flow1" doc:name="Flow1">
         <logger level="INFO" message="Flow1: processing started" doc:name="Logger"/>
         <set-payload value="Flow1 Payload" doc:name="Set Payload"/>
         <!-- Transformation payload -->
          <logger level="INFO" message="Flow1: processing finished" doc:name="Logger"/>
          <flow-ref name="Join-Flow" doc:name="Flow Reference"/>
         </sub-flow>

        <sub-flow name="Flow2" doc:name="Flow2">
        <logger level="INFO" message="Flow2: processing started" doc:name="Logger"/>
         <set-payload value="Flow2 Payload" doc:name="Set Payload"/>
         <scripting:component doc:name="Groovy">
         <scripting:script engine="Groovy"><![CDATA[sleep(2000); return message.payload;]]>    
         </scripting:script>
         </scripting:component>
          <!--  Transformation payload -->
        <logger level="INFO" message="Flow2: processing finished" doc:name="Logger"/>
         <flow-ref name="Join-Flow" doc:name="Flow Reference"/>
        </sub-flow>

        <sub-flow name="Join-Flow" doc:name="Join-Flow">
        <collection-aggregator timeout="6000" failOnTimeout="true" doc:name="Collection Aggregator"/>
        <combine-collections-transformer doc:name="Combine Collections"/>
        <logger level="INFO"  message="Combined Payload: #[message.payload]" doc:name="Logger"/>
        <set-payload value="Soap XML Response" doc:name="Set Payload"/>
        </sub-flow> 

EXCEPTION: -

[try1].ScatterGatherWorkManager.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing started
INFO  2014-08-18 13:34:24,361 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing started
INFO  2014-08-18 13:34:24,364 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Flow1: processing finished
WARN  2014-08-18 13:34:24,366 [[try1].ScatterGatherWorkManager.01] org.mule.routing.correlation.CollectionCorrelatorCallback: Correlation Group Size not set, but correlation aggregator is being used. Message is being forwarded as is
INFO  2014-08-18 13:34:24,401 [[try1].ScatterGatherWorkManager.01] org.mule.api.processor.LoggerMessageProcessor: Combined Payload: [Flow1 Payload]
INFO  2014-08-18 13:34:26,615 [[try1].ScatterGatherWorkManager.02] org.mule.api.processor.LoggerMessageProcessor: Flow2: processing finished
ERROR 2014-08-18 13:34:26,625 [[try1].connector.http.mule.default.receiver.03] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : null (java.lang.NullPointerException). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. null (java.lang.NullPointerException)
  org.mule.api.routing.AggregationContext$1:41 (null)
2. null (java.lang.NullPointerException). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
    at org.mule.api.routing.AggregationContext$1.evaluate(AggregationContext.java:41)
    at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:517)
    at org.apache.commons.collections.CollectionUtils.select(CollectionUtils.java:498)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

现在您可以看到它在删除set-property后没有合并两个流的两个有效负载.....它只获得第一个流的有效负载: - 组合有效负载:[Flow1 Payload] ..

2 个答案:

答案 0 :(得分:3)

删除async中消息处理器周围的scatter-gather范围,这确实为您进行并行化,因此您不必这样做。

编辑:同时删除处理set-property属性的MULE_CORRELATION消息处理器。 scatter-gather应该为你做到这一点。

EDIT2 :您可以移除单processor-chain周围的flow-ref:它无用。

此外,似乎对scatter-gather的作用存在深刻的误解:你强行使其子流响应收敛到单个Join-Flow,在那里聚合东西,有效地绕过和重新实现scatter-gather建议为您做的所有事情。

flow-ref移至Join-Flow,移除Join-Flow,然后将其处理逻辑(不是聚合器)放在scatter-gather之后。

答案 1 :(得分:1)

根据David的建议,最终的工作解决方案是: -

indices