Package org.springframework.retry.interceptor

Examples of org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor


    this.newMessageIdentifier = newMessageIdentifier;
  }

  public StatefulRetryOperationsInterceptor getObject() {

    StatefulRetryOperationsInterceptor retryInterceptor = new StatefulRetryOperationsInterceptor();
    RetryOperations retryTemplate = getRetryOperations();
    if (retryTemplate == null) {
      retryTemplate = new RetryTemplate();
    }
    retryInterceptor.setRetryOperations(retryTemplate);

    retryInterceptor.setNewItemIdentifier(new NewMethodArgumentsIdentifier() {
      public boolean isNew(Object[] args) {
        Message message = (Message) args[1];
        if (newMessageIdentifier == null) {
          return !message.getMessageProperties().isRedelivered();
        } else {
          return newMessageIdentifier.isNew(message);
        }
      }
    });

    final MessageRecoverer messageRecoverer = getMessageRecoverer();
    retryInterceptor.setRecoverer(new MethodInvocationRecoverer<Void>() {
      public Void recover(Object[] args, Throwable cause) {
        Message message = (Message) args[1];
        if (messageRecoverer == null) {
          logger.warn("Message dropped on recovery: " + message, cause);
        } else {
          messageRecoverer.recover(message, cause);
        }
        // This is actually a normal outcome. It means the recovery was successful, but we don't want to consume
        // any more messages until the acks and commits are sent for this (problematic) message...
        throw new ImmediateAcknowledgeAmqpException("Recovered message forces ack (if ack mode requires it): "
            + message, cause);
      }
    });

    retryInterceptor.setKeyGenerator(new MethodArgumentsKeyGenerator() {
      public Object getKey(Object[] args) {
        Message message = (Message) args[1];
        if (messageKeyGenerator == null) {
          String messageId = message.getMessageProperties().getMessageId();
          if (messageId == null) {
View Full Code Here


*/
public class RetryInterceptorBuilderSupportTests {

  @Test
  public void testBasic() {
    StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().build();
    assertEquals(3, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
  }
View Full Code Here

  }

  @Test
  public void testWithCustomRetryTemplate() {
    RetryOperations retryOperations = new RetryTemplate();
    StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
        .retryOperations(retryOperations)
        .build();
    assertEquals(3, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
    assertSame(retryOperations, TestUtils.getPropertyValue(interceptor, "retryOperations"));
  }
View Full Code Here

    assertSame(retryOperations, TestUtils.getPropertyValue(interceptor, "retryOperations"));
  }

  @Test
  public void testWithMoreAttempts() {
    StatefulRetryOperationsInterceptor interceptor =
        RetryInterceptorBuilder.stateful()
          .maxAttempts(5)
          .build();
    assertEquals(5, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
  }
View Full Code Here

    assertEquals(5, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
  }

  @Test
  public void testWithCustomizedBackOffMoreAttempts() {
    StatefulRetryOperationsInterceptor interceptor =
        RetryInterceptorBuilder.stateful()
          .maxAttempts(5)
          .backOffOptions(1, 2, 10)
          .build();
View Full Code Here

    assertEquals(10L, TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.maxInterval"));
  }

  @Test
  public void testWithCustomBackOffPolicy() {
    StatefulRetryOperationsInterceptor interceptor =
        RetryInterceptorBuilder.stateful()
          .maxAttempts(5)
          .backOffPolicy(new FixedBackOffPolicy())
          .build();
View Full Code Here

  }

  @Test
  public void testWithCustomNewMessageIdentifier() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    StatefulRetryOperationsInterceptor interceptor =
        RetryInterceptorBuilder.stateful()
          .maxAttempts(5)
          .newMessageIdentifier(new NewMessageIdentifier() {

              @Override
View Full Code Here

    assertTrue(latch.await(0, TimeUnit.SECONDS));
  }

  @Test
  public void testWitCustomRetryPolicyTraverseCause() {
    StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
        .retryPolicy(new SimpleRetryPolicy(15, Collections
            .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true), true))
        .build();
    assertEquals(15, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
  }
View Full Code Here

  }

  @Test
  public void testWithCustomKeyGenerator() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
        .messageKeyGenerator(new MessageKeyGenerator() {

            @Override
            public Object getKey(Message message) {
              latch.countDown();
View Full Code Here

TOP

Related Classes of org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.