0

I've got a spring integration pipeline and I've got a number of different service activators that I want to enable retry for.

I want to use the same retry policy (i.e. the number of retries, back-off policy, etc). Can I just have one bean that implements the retry policy and use it for several different service activators, or does each service activator need its own retry bean? In other words, can I just make one bean "retryWithBackupAdviceSession" and set it the request-hadler-advice-chain for several service activators? Or does each one need its own?

Here's an example of the retry policy I'm using.

<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>

As a follow up-question, if my service activator is running in an executor channel, does it somehow keep track of the retries per-thread? Or is there something I need to do to ensure that there isn't cross-talk between the different threads retrying on different messages on the same thread-safe service activator?

Alan Ludwig
  • 67
  • 1
  • 11
  • hi alan .. i also want to do the same can u share the whole xml config /??? #thanks – Sujeeth Damodharan Aug 27 '15 at 06:31
  • I'm afraid that I'm not able to share the configuration. I moved on from my "spring" responsibilities more than a year ago. I'm doing embedded C+ these days. I'm terribly sorry. – Alan Ludwig Aug 28 '15 at 15:36

2 Answers2

0

You go right way: the RequestHandlerRetryAdvice is thread-safe, so you can use the same beand from several places.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
0

I had to implement Retry mechanism in my project as well and I created my own implementation.

Retry using AOP

This works like a charm.

You can just annotate your methods with the @Retry annotation, provide some config you want and its done.

Community
  • 1
  • 1
Vivek Kothari
  • 462
  • 6
  • 20