Announcement Announcement Module
Collapse
No announcement yet.
Custom retry operation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom retry operation

    Hi all,
    I need to implement a custom retry template in my spring integration project.What I am trying to achieve is to retry my messages using a backoff policy and I need to avoid the retry if it is due to certain exception.

    What can I do accomplish this??


    Thanks

  • #2
    Hello!

    For a start let me send you to the documentations:
    http://static.springsource.org/sprin...tml/retry.html
    http://static.springsource.org/sprin...r-advice-chain
    To achieve your requirements
    need to avoid the retry if it is due to certain exception
    It is a responsibility of RetryPolicy:
    Code:
    MyRetryPolicy extends SimpleRetryPolicy {
       public boolean canRetry(RetryContext context) {
           return !(context.getLastThrowable() instanceof MyException) && super.canRetry(context);
       }
    }
    Is it what are you looking for?

    Take care,
    Artem

    Comment


    • #3
      Thanks cleric. That did the job for me. Although I had to dig out "myexception" from context.getLastThrowable() .

      cheers

      Comment


      • #4
        I encounter this problem too. that's what i solved it:

        Because spring-amqp wrap business exceptions into ListenerExecutionFailedException, So we register wrapped business exceptions instead of throwed ListenerExecutionFailedException itself.

        Code:
        public class CustomRetryPolicy extends SimpleRetryPolicy {
        
            public CustomRetryPolicy() {
                super();
            }
        
            public CustomRetryPolicy(int maxAttempts,
                    Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
                super(maxAttempts, retryableExceptions);
            }
        
            @Override
            public void registerThrowable(RetryContext context, Throwable throwable) {
                super.registerThrowable(context, throwable!=null && throwable.getCause()!=null ? throwable.getCause() : throwable);
            }
        
        }
        Config of retryTemplate:
        Code:
          <bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
            <property name="backOffPolicy">
              <bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
                <property name="backOffPeriod" value="10000" />
              </bean>
            </property>
            <property name="retryPolicy">
              <bean class="com.xxx.email.service.message.impl.CustomRetryPolicy">
                <constructor-arg name="maxAttempts" value="3" />
                <constructor-arg name="retryableExceptions" ref="retryableExceptions" />
              </bean>
            </property>
          </bean>
        
          <util:map id="retryableExceptions"  map-class="java.util.HashMap" >
            <entry key="com.xxx.email.service.message.exception.SMTPException" value="true" />
          </util:map>
        that's work fine for me.

        Comment

        Working...
        X