【问题标题】:Spring Integration & Retry: Do I need a separate retry bean for each service-activator?Spring Integration & Retry:我是否需要为每个服务激活器使用单独的重试 bean?
【发布时间】:2014-01-27 23:00:21
【问题描述】:

我有一个 Spring 集成管道,并且我有许多不同的服务激活器,我想为其启用重试。

我想使用相同的重试策略(即重试次数、退避策略等)。我可以只有一个实现重试策略的 bean 并将其用于多个不同的服务激活器,还是每个服务激活器都需要自己的重试 bean?换句话说,我可以只制作一个 bean“retryWithBackupAdviceSession”并将其设置为多个服务激活器的 request-hadler-advice-chain 吗?还是每个人都需要自己的?

这是我正在使用的重试策略的示例。

<bean id="retryWithBackoffAdviceSession" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
            <property name="retryTemplate">
                <bean class="org.springframework.retry.support.RetryTemplate">
                    <property name="backOffPolicy">
                        <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                            <property name="initialInterval" value="2000" />    <!-- 2 seconds -->
                            <property name="multiplier" value="2" />            <!-- double the wait each time -->
                            <property name="maxInterval" value="30000"/>        <!-- maximum of 30 seconds -->
                        </bean>
                    </property>
                    <property name="retryPolicy">
                        <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
                            <property name="maxAttempts" value="3"/>
                        </bean>
                    </property>
                </bean>
            </property>
            <property name="recoveryCallback">
                <bean class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
                    <constructor-arg ref="myErrorChannel"/>
                </bean>
            </property>
        </bean>

作为后续问题,如果我的服务激活器在执行器通道中运行,它是否会以某种方式跟踪每个线程的重试次数?或者我需要做些什么来确保在同一个线程安全服务激活器上重试不同消息的不同线程之间没有串扰?

【问题讨论】:

  • 嗨艾伦..我也想做同样的事情你能分享整个xml配置吗/??? #谢谢
  • 恐怕无法共享配置。一年多前,我从“春天”的职责中走出来。这些天我在做嵌入式 C+。非常抱歉。

标签: spring-integration spring-retry


【解决方案1】:

你走对了:RequestHandlerRetryAdvice 是线程安全的,所以你可以在多个地方使用同一个 bean。

【讨论】:

    【解决方案2】:

    我也必须在我的项目中实现重试机制,并且我创建了自己的实现。

    Retry using AOP

    这就像一个魅力。

    您可以使用 @Retry 注释来注释您的方法,提供一些您想要的配置并完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多