【问题标题】:Does applying ExpressionEvaluatingRequestHandlerAdvice supress the error?应用 ExpressionEvaluatingRequestHandlerAdvice 是否会抑制错误?
【发布时间】:2016-01-21 14:09:35
【问题描述】:

适配器连接到 jms 队列。我有一些逻辑需要在成功交付和故障转移时触发,因此我已将适配器连接到 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" />

我有一个连接到 failureChannel 的服务激活器,它只是改变了一个单例。我在这里所做的任何事情都不会触发错误。此外,返回的错误肯定是队列访问,所以它不可能是我在激活故障转移启动器后所做的任何事情。

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

如果我应该在 RequestHandlerRetryAdvice 或这个上使用 recoveryCallback 来实际停止错误,我会感到非常困惑。但即使成功,我也确实需要采取行动,因此 ExpressionEvaluatingAdvice 更适合我的场景。

提前感谢您的帮助:-)

【问题讨论】:

    标签: spring jms spring-integration aop


    【解决方案1】:

    这是默认行为。有关trapException 属性,请参阅ExpressionEvaluatingRequestHandlerAdvice javadocs...

    /**
     * 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;
    }
    

    我会在参考手册中添加一个注释。

    【讨论】:

    • 它正在工作!太感谢了。我可以删除我现在在上游进行的所有丑陋错误处理:-)
    猜你喜欢
    • 2021-10-14
    • 2021-12-17
    • 2019-02-08
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-04
    相关资源
    最近更新 更多