0

I've set a couple of retry configurations in my application.properties file. However, none of them is working when I ran the ribbon application.

//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;
    }
}

Here is my RibbonAppApplication class:

@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();
    }
}

This is the application.properties for the RibbonAppApplication:

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

Thank you guys so much for helping!

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Kuge4399
  • 69
  • 1
  • 8

2 Answers2

0

Missing dependency of Sprint Retry is almost always the reason for Ribbon not able to retry. Spring Retry a dependency for retry functionality for Zuul/Ribbon.

When a request fails, you may want to have the request be retried automatically. To do so when using Sping Cloud Netflix, you need to include Spring Retry on your application’s classpath. When Spring Retry is present, load-balanced RestTemplates, Feign, and Zuul automatically retry any failed requests (assuming your configuration allows doing so)

Adding Spring Retry to pom.xml should fix this.

Related docs: https://cloud.spring.io/spring-cloud-netflix/multi/multi_retrying-failed-requests.html

narendra-choudhary
  • 4,582
  • 4
  • 38
  • 58
0

You have to add the spring-retry dependency to your pom.xml file:

<!-- 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>
veben
  • 19,637
  • 14
  • 60
  • 80