Results 1 to 4 of 4

Thread: Custom retry operation

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Posts
    16

    Default 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. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    637

    Default

    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

  3. #3
    Join Date
    Aug 2012
    Posts
    16

    Default

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

    cheers

  4. #4
    Join Date
    Nov 2012
    Posts
    18

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •