【问题标题】:Ribbon MaxAutoRetries properties is not working功能区 MaxAutoRetries 属性不起作用
【发布时间】:2019-04-05 07:52:14
【问题描述】:

我在application.properties 文件中设置了几个重试配置。但是,当我运行功能区应用程序时,它们都不起作用。

//this is my service
@RestController
@SpringBootApplication
public class HelloApplication {
    @Value("${server.port}")
    private int port;

    public static void main(String[] args) {
        SpringApplication.run(HelloApplication .class, args);
    }
    @GetMapping(value="/app")
    public String notification() {
        return "This Is HelloService running on port:"+ port;
    }
}

这是我的RibbonAppApplication 课程:

@SpringBootApplication(scanBasePackages={"com.netflix.client.config.IClientConfig"})
@RestController
@RibbonClient(name= "hello", configuration=RibbonConfig.class )
public class RibbonAppApplication {
    @Autowired
    private RestTemplate restTemplate;
    public static void main(String[] args) {
        SpringApplication.run(RibbonAppApplication.class, args);
    }
    @GetMapping
    public String getService() {
        return restTemplate.getForObject("http://hello/app",String.class);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

这是RibbonAppApplicationapplication.properties

ribbon.eureka.enabled=false
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

hello.ribbon.listOfServers=http://localhost:1111, http://localhost:2222
hello.ribbon.OkToRetryOnAllOperations=false
hello.ribbon.MaxAutoRetries=0
hello.ribbon.MaxAutoRetriesNextServer=1

非常感谢你们的帮助!

【问题讨论】:

    标签: spring-boot spring-cloud resttemplate netflix-ribbon


    【解决方案1】:

    缺少 Sprint Retry 的依赖项几乎总是 Ribbon 无法重试的原因。 Spring 重试 Zuul/Ribbon 重试功能的依赖项。

    当请求失败时,您可能希望自动重试请求。要在使用 Sping Cloud Netflix 时这样做,您需要在应用程序的类路径中包含 Spring Retry。当 Spring Retry 存在时,负载均衡的 RestTemplates、Feign 和 Zuul 会自动重试任何失败的请求(假设您的配置允许这样做)

    向 pom.xml 添加 Spring Retry 应该可以解决这个问题。

    相关文档:https://cloud.spring.io/spring-cloud-netflix/multi/multi_retrying-failed-requests.html

    【讨论】:

      【解决方案2】:

      您必须将 spring-retry 依赖项添加到您的 pom.xml 文件中:

      <!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
      <dependency>
          <groupId>org.springframework.retry</groupId>
          <artifactId>spring-retry</artifactId>
          <version>1.2.4.RELEASE</version>
      </dependency>
      

      【讨论】:

        猜你喜欢
        • 2011-11-03
        • 2018-10-11
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-31
        • 1970-01-01
        相关资源
        最近更新 更多