2016-10-10 78 views
0

试图找出递归调用骡流的正确方法。递归调用骡流

我们有一个流程,它在运行时构建一个工作数组,然后在“For Each”块内使用“流参考”递归调用自身。问题是,我们还没有找到将参数传递给这个递归流的正确方法,所以我们没有得到我们期望的结果。

我们尝试使用流属性(Groovy中的setInvocationParameter())传递参数,但它似乎是跨流的多个实例共享的。 例如,我们有ForEach数组迭代包含[2的数组。 3. 4],但取决于时机,这些值中的一些会丢失(我们通常会看到2,然后是4次 - 跳过3)。

我们尝试过不同的骡子处理策略,没有任何运气。 Mule的默认排队异步存在上述问题。同步似乎不起作用(有意义,因为我们的递归模型可能需要两个实例至少运行)。

下面是配置XML的相关部分(整个流程非常大)。在流的结尾是这样的:

<foreach collection="#[sessionVars['actionArray']]" 
     counterVariableName="actionIndex" 
     rootMessageVariableName="actionVar" doc:name="For Each"> 
    <scripting:component doc:name="Run Each Action"> 
    <scripting:script engine="Groovy"> 
     <![CDATA[def aa = message.getSessionProperty('actionArray') 
     def this_item = aa.get(message.getInvocationProperty('actionIndex')) 
     // Pass the desired action for the recursive call 
     message.setInvocationProperty('FlowAction', this_item) 
     log.info "Running $this_item" // <- Shows the correct item 
     return]]> 
    </scripting:script> 
    </scripting:component> 
    <flow-ref name="DoAction" doc:name="Do Action"/> 
</foreach> 

在流的前部,有一个显示“FlowAction”流量变量的记录器。当我们用[2,3,4]阵列测试时,这个记录器语句被驱动三次(如预期的那样),但通常使用值2,4和4.

我们在Mule 3.7上得到了相同的结果和一个旧的3.4系统(都是社区版)。

感谢从骡行家那里任何建议...

+0

你可以发布你的xml吗? –

回答

0

我不知道这是100%正确的,但在这里就是我们所做的......

花了很多时间试图获得“对于每一个”和“后流量参考“方法可靠地工作,我们放弃了并转向了另一种技术。我们的选择是从短Groovy脚本递归地删除每个块,并驱动流量:

 . . . 

    // Invoke the flow recursively for every item in the array 

    Flow flow = muleContext.getRegistry().lookupFlowConstruct("flow name") 
    actions.each // actions is an array of integers built earlier 
    { item-> 
      MuleMessage msg = message.createInboundMessage() 
      DefaultMuleSession sess = new DefaultMuleSession(flow, muleContext) 
      DefaultMuleEvent event = new DefaultMuleEvent(msg, MessageExchangePattern.ONE_WAY, sess) 

      // Copy the current inbound properties to the new message 

      message.getInboundPropertyNames().each 
      { 
      event.getMessage().setProperty(it, message.getInboundProperty(it), PropertyScope.INBOUND) 
      } 

      // Copy the current session variables to the new message too 

      message.getSessionPropertyNames().each 
      { 
      event.setSessionVariable(it, message.getSessionProperty(it)) 
      } 

      // Now set the item we want processed as a flow variable 

      event.setFlowVariable("Action", item.toString()) 

      // Finally, trigger the flow (which runs asynchronously) 

      flow.process(event).getMessage() 
    } 

这是在我们的环境现在能正常使用。

-2

需要这方面的一些详细信息,如何ü发送输入到这个,因为我们可以看到它是GUVEN为sessionVars [“actionarray”] 。 你能否让我知道,以便我们可以对此进一步分析。

感谢 纳文

+0

流程的其他部分在将要做的工作的会话变量中创建一个数组...这些只是对应于数据库表中的行的整数值。我们相当肯定这是正确的 - 上面的Groovy脚本中的log.info显示了正确的值。当flow-ref所针对的流程运行时,第一步是一个记录器组件,在这里我们看到了意想不到的结果。 –