2016-10-10 75 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所針對的流程運行時,第一步是一個記錄器組件,在這裏我們看到了意想不到的結果。 –