标签: spring-retry

哪些HTTP错误永远不会触发自动重试?

我正在尝试使一些微服务更具弹性,并且重试某些类型的HTTP请求将有助于此.

重试超时会给客户带来非常缓慢的体验,因此我不打算在这种情况下重试.重试400s无济于事,因为错误的请求在几毫秒后仍然是一个错误的请求.

我想还有其他原因不能重试一些其他类型的错误,但是哪些错误以及为什么?

http httpresponse spring-retry hystrix microservices

13
推荐指数
2
解决办法
4378
查看次数

如何使spring @retryable可配置?

我有这段代码

@Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class,
        exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) )
public void testThatService(String serviceAccountId)
        throws ServiceUnavailableException, URISyntaxException {
Run Code Online (Sandbox Code Playgroud)

//这里的一些实现}

有没有办法可以使用@Value配置maxAttempts,延迟和乘数?或者是否有任何其他方法可以使注释中的这些字段可配置?

java spring spring-retry

12
推荐指数
4
解决办法
2万
查看次数

如何在Spring Boot中将配置属性注入Spring Retry注释?

在spring启动应用程序中,我在yaml文件中定义了一些配置属性,如下所示.

my.app.maxAttempts = 10
my.app.backOffDelay = 500L
Run Code Online (Sandbox Code Playgroud)

还有一个例子bean

@ConfigurationProperties(prefix = "my.app")
public class ConfigProperties {
  private int maxAttempts;
  private long backOffDelay;

  public int getMaxAttempts() {
    return maxAttempts;
  }

  public void setMaxAttempts(int maxAttempts) {
    this.maxAttempts = maxAttempts;
  }

  public void setBackOffDelay(long backOffDelay) {
    this.backOffDelay = backOffDelay;
  }

  public long getBackOffDelay() {
    return backOffDelay;
  }
Run Code Online (Sandbox Code Playgroud)

我怎么能注入的价值观my.app.maxAttemptsmy.app.backOffdelay对春重试注解?在下面的示例中,我想用配置属性的相应引用替换10maxAttempts和500Lbackoff值的值.

@Retryable(maxAttempts=10, include=TimeoutException.class, backoff=@Backoff(value = 500L))
Run Code Online (Sandbox Code Playgroud)

java spring spring-retry spring-boot

12
推荐指数
2
解决办法
7066
查看次数

Spring Retryable注释ClassNotFoundException

我想使用@Retryable注释restTemplate.我已经添加:

<dependency>
       <groupId>org.springframework.retry</groupId>
       <artifactId>spring-retry</artifactId>
       <version>1.2.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

以及@EnableRetry配置类.我标记了方法:

restTemplate.exchange(url, HttpMethod.POST, request, String.class);
Run Code Online (Sandbox Code Playgroud)

用(在一个新的主题中)

@Retryable(maxAttempts=4,value=Exception.class,backoff=@Backoff(delay = 2000))
Run Code Online (Sandbox Code Playgroud)

但我从catalina得到错误:

27-Oct-2017 18:11:41.023 SEVERE [http-nio-8080-exec-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
    at 
<ommitted>
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is …
Run Code Online (Sandbox Code Playgroud)

java spring spring-retry spring-boot

11
推荐指数
2
解决办法
3850
查看次数

Springboot @retryable没有重试

以下代码未重试.我错过了什么?

@EnableRetry
@SpringBootApplication
public class App implements CommandLineRunner
{
    .........
    .........


    @Retryable()
    ResponseEntity<String> authenticate(RestTemplate restTemplate, HttpEntity<MultiValueMap<String, String>> entity) throws Exception
    {
        System.out.println("try!");
        throw new Exception();
        //return restTemplate.exchange(auth_endpoint, HttpMethod.POST, entity, String.class);
    }
Run Code Online (Sandbox Code Playgroud)

我已将以下内容添加到pom.xml中.

    <dependency>
        <groupId>org.springframework.retry</groupId>
        <artifactId>spring-retry</artifactId>
        <version>1.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我也试过为@Retryable提供不同的参数组合.

@Retryable(maxAttempts=10,value=Exception.class,backoff=@Backoff(delay = 2000,multiplier=2))
Run Code Online (Sandbox Code Playgroud)

谢谢.

java spring maven spring-retry spring-boot

10
推荐指数
6
解决办法
2万
查看次数

注解方式注册监听到spring的@Retryable

如何spring-retry使用@Retryable()注解注册监听器?

@Bean
public RetryListener myRetryListener() {
    return new MyRetryListener();
}

@Service
public class SampleService {
   private int cnt = 1;

   @Retryable(RuntimeException.class)
   public void retryMethod(int x) throws Exception {
      System.out.println("SampleService invoked.");
      Thread.sleep(500);

      if (cnt++ < 4) {
        throw new RuntimeException("SampleService throwing exception");
      }
   }

}
Run Code Online (Sandbox Code Playgroud)

如果我创建任何侦听器 bean,它会自动注册到RetryTemplate. 因此,如果我有多个侦听器,那么如何要求特定侦听器侦听我的可重试服务?

java spring-retry

10
推荐指数
2
解决办法
7909
查看次数

使用Transactional进行Spring重试

Spring Retry是否可以保证与Spring的@Transactional注释一起使用?

具体来说,我正在尝试使用@Retryable乐观锁定.似乎它将依赖于创建的AOP代理的顺序.例如,如果调用如下所示:

调用代码 - >重试代理 - >事务代理 - >实际数据库代码

然后它将正常工作,但如果代理结构如下:

调用代码 - >事务代理 - >重试代理 - >实际数据库代码

然后重试将不起作用,因为关闭事务的行为是抛出optmistic锁定异常的行为.

在测试中,它似乎生成了第一个案例(重试,然后交易),但我不知道这是保证行为还是幸运.

java spring spring-data spring-retry

10
推荐指数
3
解决办法
4276
查看次数

根据结果​​重试方法(而不是异常)

我有一个具有以下签名的方法:

public Optional<String> doSomething() {
    ...
}
Run Code Online (Sandbox Code Playgroud)

如果我得到一个空的,Optional我想重试这个方法,只有在 3 次后才返回空的Optional

我查看并找到了Retryablespring 注释,但它似乎只适用于异常。

如果可能的话,我想为此使用一个库,并避免:

  • 创建和抛出异常。
  • 自己写逻辑。

java spring spring-retry

10
推荐指数
1
解决办法
5402
查看次数

是否可以根据HttpStatus状态代码在spring-retry中设置RetryPolicy?

是否可以根据错误状态代码在spring retry(https://github.com/spring-projects/spring-retry)中设置RetryPolicy ?例如我要重试上HttpServerErrorExceptionHttpStatus.INTERNAL_SERVER_ERROR状态码,其是503因此,应忽略所有其他错误代码- [500 - 502]和[504 - 511].

spring spring-retry

9
推荐指数
2
解决办法
5307
查看次数

Spring @Retryable - 如何在调用时记录?

我用compile 'org.springframework.retry:spring-retry:1.2.2.RELEASE'Spring Boot 1.5.9.RELEASE.

配置为重试我的方法,它运作良好:

@Retryable(value = { IOException.class }, maxAttempts = 5, backoff = @Backoff(delay = 500))
public void someMethod(){...}
Run Code Online (Sandbox Code Playgroud)

重试发生时如何输出某些特定消息?

spring spring-retry spring-boot

9
推荐指数
2
解决办法
7000
查看次数