2015-10-22 34 views
2

適配器發送到jms隊列。我有一些邏輯需要在成功交付和故障轉移時觸發,因此我已將適配器掛接到ExpressionEvaluatingRequestHandlerAdvice。應用ExpressionEvaluatingRequestHandlerAdvice是否會抑制錯誤?

<jms:outbound-channel-adapter id="101Out" 
           channel="101DestinationChannel" 
           connection-factory="101Factory" 
           destination-expression="headers.DESTINATION_NAME" 
           destination-resolver="namingDestinationResolver" 
           explicit-qos-enabled="true"> 
    <jms:request-handler-advice-chain> 
     <beans:bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"> 
      <beans:property name="onSuccessExpression" ref="success"/> 
      <beans:property name="successChannel" ref="normalOpsReplicationChannel"/> 
      <beans:property name="onFailureExpression" ref="failure"/> 
      <beans:property name="failureChannel" ref="failoverInitiationChannel" /> 
     </beans:bean> 
     <beans:bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">> 
      <beans:property name="retryTemplate" ref="retryTemplate"/> 
     </beans:bean> 
    </jms:request-handler-advice-chain>  
</jms:outbound-channel-adapter> 

現在這兩種方法都正確觸發並且複製/故障切換邏輯執行正常。但是如果失敗(當我停止隊列管理器時),一旦進程連接到failureChannel完成,我就會看到錯誤正在傳播回調用源(本例中爲HTTP端點)。

該建議是應該阻止錯誤傳播的權利?

<service-activator input-channel="failoverInitiationChannel" 
     ref="failoverInitiator" /> 

我有一個服務激活器連接到只改變一個singleton的failureChannel。我在這裏做的任何事都可能引發錯誤。而且,返回的錯誤肯定是用於隊列訪問的,因此在failoverInitiator激活後,我不能做任何事情。

org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'APFDEV1' with connection mode 'Client' and host name 'localhost(1510)'. 

我是一個很困惑,如果我應該使用recoveryCallback上RequestHandlerRetryAdvice或這一個真正停止錯誤。但是我確實需要採取即使在成功時也採取的行動,所以ExpressionEvaluatingAdvice更適合我的場景。

感謝您的幫助提前:-)

回答

1

這是默認行爲。請參閱ExpressionEvaluatingRequestHandlerAdvice Javadoc文檔trapException財產...

/** 
* If true, any exception will be caught and null returned. 
* Default false. 
* @param trapException true to trap Exceptions. 
*/ 
public void setTrapException(boolean trapException) { 
    this.trapException = trapException; 
} 

我會添加註釋的參考手冊。

+0

它的工作!非常感謝。我可以刪除所有醜陋的錯誤處理我現在做上游:-) – alokraop