1

我只想在出现 ConnectionException 的情况下对服务激活器进行认真的重试,对于其他异常,我不想使用重试或非常轻的重试。我可以使用什么配置?我的配置的本质如下:

<int:channel id="sDZCreationErrorChannel">
    <int:interceptors>
        <int:wire-tap channel="errorLogger"/>
    </int:interceptors>
</int:channel>

<int:channel id="sDZConnectionErrorChannel">
    <int:interceptors>
        <int:wire-tap channel="errorLogger"/>
    </int:interceptors>
</int:channel>

<int:chain input-channel="sDZCreationErrorChannel" output-channel="outboundMailChannel">
    <int-mail:header-enricher>
        <int-mail:to value="${integration.sdz.email.to}"/>
        <int-mail:subject value="${integration.sdz.email.subject.creation}"/>
    </int-mail:header-enricher>
    <int:transformer ref="integrationEmailTransformer" method="transformToEmail"/>
</int:chain>

<int:chain input-channel="sDZConnectionErrorChannel" output-channel="outboundMailChannel">
    <int-mail:header-enricher>
        <int-mail:to value="${integration.sdz.email.to}"/>
        <int-mail:subject value="${integration.sdz.email.subject.noconnection}"/>
    </int-mail:header-enricher>
    <int:transformer ref="integrationEmailTransformer" method="transformToEmail"/>
</int:chain>

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

<!-- Processing Creation Chain -->
<int:chain input-channel="sDZCreationChannel" output-channel="debugLogger" 
    auto-startup="#{environment.getProperty('sd.zoo.enabled') == 'connect'}">
    <int:poller fixed-delay="500" />
    <int:filter ref="sDZIntegrationExistingRequestSentFilter" method="filter"/>
    <int:transformer ref="sDZCreationTransformer" method="transformOrder"/>
    <int:service-activator ref="sDZCreationServiceImpl" method="activateConfirmationCodes">
        <int:request-handler-advice-chain>
            <ref bean="retryAdvice"/>
        </int:request-handler-advice-chain>
    </int:service-activator>
</int:chain>

<int:exception-type-router input-channel="errorChannel" default-output-channel="integrationDeadLetterErrorChannel">
    <int:mapping exception-type="com.smartdestinations.connect.integration.exception.sdz.SDZCreationResponseException" channel="sDZCreationErrorChannel"/>
    <int:mapping exception-type="com.smartdestinations.connect.integration.exception.sdz.SDZConnectionException" channel="sDZConnectionErrorChannel"/>
</int:exception-type-router>
4

1 回答 1

1

不,您不能将一个重试建议与其他建议一起使用。该<request-handler-advice-chain>策略是按照它们在<request-handler-advice-chain>. 因此,如果您先声明一个retryAdvice,然后再声明另一个,则在第二个完成工作之前不会到达第一个。

我还没有看到如何轻松满足您的要求的全貌,但我真的确定您应该处理 custom RetryPolicy,您可以通过以下方式达到目标异常:

public boolean canRetry(RetryContext context) {
    Throwable t = context.getLastThrowable();
    ...
}

注意那个有用的RetryContext对象。

还有一个感兴趣的钩子作为RetryListener抽象,您可以使用它在其中设置一些附加属性RetryContext。例如在 SI 中RequestHandlerRetryAdvice

public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
    context.setAttribute("message", messageHolder.get());
    return true;
}
于 2016-07-19T19:58:43.313 回答