2015-10-22 33 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