2013-02-07 62 views
0

給定一個配置有任務執行器的發佈 - 訂閱通道,如果拋出異常,是否有可能中斷其訂購訂閱者的調用?彈簧整合:有序訂閱者發佈/訂閱通道的異常處理

例如,在此示例中,'已處理'消息仍然由序列中的第二個服務激活器發送。我希望這不會發生。

<int:publish-subscribe-channel id="input" task-executor="taskExecutor" /> 

    <int:service-activator 
     input-channel="input" 
     order="1" 
     expression="1/0" 
     output-channel="nullChannel" 
    /> 
    <int:service-activator 
     input-channel="input" 
     order="2" 
     expression="'worked'" 
     output-channel="output" 
    /> 

    <int:channel id="output"> 
     <int:queue /> 
    </int:channel> 

現實世界中的用例是稍微複雜一些,在一個File發佈到兩個用戶,一個用於解析它的內容,另一個用於歸檔到S3。應用了一個序列,以便可以在兩個任務完成後進行彙總和刪除。

S3上傳通過一個沒有回覆的出站通道適配器來實現。因此,有一個發佈 - 訂閱頻道首先調用S3適配器(使用order屬性),然後將File發送到網橋,然後網橋將其放置在收集聚合消息的頻道上。

如果S3上傳失敗,我不希望該文件被刪除,所以不能調用上行通道的第二個用戶。

回答

1

添加任務執行程序時,「order」屬性確實沒有意義,因爲這兩個任務都是異步執行的;打斷「第二」線程可能爲時已晚。要回答您的一般問題,不,一個線程上的故障不會中斷其他線程。

如果我正確理解你的使用情況,你應該能夠做到你想要使用的是什麼2.2 <request-handler-advice-chain/>新的功能,在這裏你可以添加一個ExpressionEvaluatingRequestHandlerAdvice採取不同的行動的基礎上,成功或失敗。這是在這個博客中討論... http://blog.springsource.org/2012/10/09/spring-integration-2-2-retry-and-more/,特別是它參考的示例代碼(對於ftp適配器)...

<int-ftp:outbound-channel-adapter 
    channel="inputChannel" 
    session-factory="mockSessionFactory" 
    remote-directory="foo"> 
    <int-ftp:request-handler-advice-chain> 
     <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"> 
      <property name="onSuccessExpression" value="payload.delete()" /> 
      <property name="successChannel" ref="afterSuccessDeleteChannel" /> 
      <property name="onFailureExpression" value="payload.renameTo(payload.absolutePath + '.failed.to.send')" /> 
      <property name="failureChannel" ref="afterFailRenameChannel" /> 
     </bean> 
    </int-ftp:request-handler-advice-chain> 
</int-ftp:outbound-channel-adapter> 
+0

謝謝加里。在我的測試示例中工作,但可悲的是Amol的AWS擴展不支持request-handler-advice-chain呢! –

+0

我對適配器並不熟悉,但是,除非命名空間支持建議鏈,否則您應該能夠使用 s代替它 - 您只需將處理程序(和建議鏈)注入到ConsumerEndpointFactoryBean中即可。 –

+0

Gary,「ExpressionEvaluatingRequestHandlerAdvice」是不是將原始標頭傳遞給'AdviceMessage'的構造函數?結果,我失去了一個相關標題。 –