2014-09-24 61 views
1

我有以下工作流程。報頭彙總期間錯誤通道和回覆通道消失

  1. 入站通道

  2. 分離器

  3. 用於分割的通道任務執行器 - 所有線程執行相同的工作流程。

3.a.構建請求

3.b.網關消息端點的服務激活器包裝器。

3.c.通過配置error-channel的http-outbound-gateway上的網關包裝器(在調用http-outbound-gateway時處理異常)

3.d. HTTP的出站網關

  • 聚合

  • 響應出彈簧集成的工作流程。

  • 如果在3.d中發生異常,則控件轉到爲網關錯誤通道配置的服務激活器。 我只將以下內容從失敗的消息複製到傳遞給錯誤通道的標題的新標題。

    a。相關ID b。序列號 c。 sequenceSize

    但是,在聚合分離器響應時,DefaultAggregatingMessageGroupProcessor.java將刪除衝突的標題,並通過它在將控件提供給聚合器之前刪除錯誤通道和回覆通道。

    因此,一旦聚合器完成它的操作,它無法找到答覆或錯誤通道,並導致異常。

    我正在使用spring-integration-core 2.2.1版本,我不確定爲什麼回覆通道和錯誤通道在標題聚合過程中被刪除。

    解決此問題的任何輸入都會有很大的幫助。

    謝謝:)

    編輯1: 非常感謝你加里幫助我完成這個場景。我分享我的當前配置

    <!-- SPLITTER --> 
    <int:splitter id="dentalSplitter" ref="dentalServiceSplitter" 
        method="getDentalServiceList" input-channel="dentalServiceSplitterChannel" 
        output-channel="dentalSplitterTaskChannel" /> 
    
    <int:channel id="dentalSplitterTaskChannel"> 
        <int:dispatcher task-executor="dentalTaskExecutor" /> 
    </int:channel> 
    
    <int:chain input-channel="dentalSplitterTaskChannel" output-channel="dentalGatewayChannel"> 
        <int:header-enricher> 
         <int:header name="CHAIN_START_TIME" expression="T(System).currentTimeMillis()" overwrite="true" /> 
        <int:object-to-json-transformer content-type="application/json"/>    
    </int:chain> 
    
    <int:service-activator input-channel="dentalGatewayChannel" ref="dentalGatewayWrapper" output-channel="dentalReplyChannel" /> 
    <int:gateway id="dentalGatewayWrapper" default-request-channel="dentalCostEstimateRequestChannel" error-channel="dentalErrorChannel"/> 
    
    <int-http:outbound-gateway id="dentalGateway" 
        url-expression="@urlBuilder.build('${service.endpoint}')" 
        http-method="POST" request-factory="clientHttpRequestFactory" 
        request-channel="dentalCostEstimateRequestChannel" extract-request-payload="true" 
        expected-response-type="com.dental.test.DentalResponse"> 
        <int-http:request-handler-advice-chain> 
         <ref bean="logChainTimeInterceptor" /> 
        </int-http:request-handler-advice-chain> 
    </int-http:outbound-gateway> 
    
    <!-- EXCEPTION --> 
    <int:chain input-channel="dentalErrorChannel" output-channel="dentalAggregatorChannel"> 
        <int:transformer ref="commonErrorTransformer" method="dentalGracefulReturn"/> 
    </int:chain> 
    
    <!-- SUCCESS --> 
    <int:chain input-channel="dentalReplyChannel" output-channel="dentalAggregatorChannel"> 
         <int:filter discard-channel="dentalErrorChannel" 
         expression="T(com.dental.util.InvocationOutcomeHelper).isOutcomeSuccess(payload?.metadata?.outcome?.code,payload?.metadata?.outcome?.message)" /> 
    </int:chain> 
    
    <!-- AGGREGATION --> 
    
    <int:chain input-channel="dentalAggregatorChannel" output-channel="wsDentalServiceOutputChannel" > 
        <int:aggregator ref="dentalServiceAggregator" /> 
        <int:service-activator ref="dentalResponseServiceActivator" /> 
    </int:chain> 
    

    什麼我注意到這一點,通過網關當每個分流道中產生錯誤和答覆,並從網關得到響應後回一個新的臨時通道,它保留了保留(原始入站)錯誤和回覆通道頭。正如你所提到的那樣,在控制到達錯誤轉換器後,保留保留標題的流程被破壞,並且聚合消息組處理器接收到三個不同的臨時通道實例,並將其刪除。 我打算有一個自定義消息組處理器,並修改用於聚合頭的衝突解決策略,並提出了此配置。

    <bean id="channelPreservingAggregatingMessageHandler" class="org.springframework.integration.aggregator.AggregatingMessageHandler"> 
        <constructor-arg name="processor" ref="channelPreservingMessageGroupProcessor"/> 
    </bean> 
    

    雖然我還沒有測試過。但基於這個討論,這看起來不是一個可行的解決方案。

    看起來像我的網關配置錯誤處理不正確。 但是,我對你的這個陳述感到困惑「不要直接轉發消息,只需處理錯誤流中的錯誤並將結果正常地返回給網關」包裝器「。如果我刪除了錯誤通道,當發生異常時如何恢復控制權?可能是我錯過了解這裏的一些東西。你能詳細解釋一下嗎?

    回答

    2

    當詢問有關這種情況的問題時,通常需要顯示您的配置。但是,我懷疑您是將錯誤流中的消息直接轉發給聚合器。

    這就好比在代碼中做GOTO並打破了範圍。

    這將不起作用,因爲錯誤消息中的replyChannel標頭用於網關「包裝器」,而不是原始上游入站網關。當聚合器獲得衝突的頭部時,它別無選擇,只能丟棄頭部(您將看到一個DEBUG日誌消息)。

    而不是直接轉發消息,只需處理錯誤流中的錯誤並正常返回結果到網關「包裝」(簡單地省略錯誤流最後一個元素上的錯誤通道)。

    然後,網關將修復回覆,以便與其他消息(好的和壞的)一致並將其轉發給聚合器。

    您不需要混淆錯誤流中的標題,只需返回想要彙總的值以及良好的結果。

    你應該更新到current release,或者至少是2.2.x行(2.2.6)中的最新版本。

    +0

    嗨,加里我已經提供了關於編輯的更多信息。如果我能正確理解並朝着正確的方向前進,您能否讓我知道? – 2014-09-25 13:52:23

    +0

    否;這是行不通的 - 正如我猜測的那樣,你正在跳出子流(網關「包裝器」的下游)。你不能那樣做;你必須返回一個值給網關,例如通過從EXCEPTION鏈中刪除'output-channel'。然後,您需要在s-a之後使用某種路由器,以確定是應該轉到「dentalReplyChannel」還是直接轉到聚合器。您不能在兩個地方使用同一個EXCEPTION鏈,因爲在過濾器的情況下,您最終需要路由到聚合器。 – 2014-09-25 14:25:41

    +0

    謝謝你的見解。我已經移除了錯誤處理變換器周圍的鏈,以便控制器在錯誤處理後返回到網關。 ** **這又將取代保留的錯誤和回覆頭信道。 – 2014-09-25 18:11:44