2

Changing a work project's version to java 17 resulted in the need to increase the spring-cloud-starter-openfeign to 3.0.6 (part of the 2020.0.0 Spring Cloud release train). Since Spring Cloud Netflix Ribbon has been deprecated and is not included in the 2020.0.0 release train, I have to make some changes in my project and switch to using Spring Cloud LoadBalancer.

After reading some articles I got the following understanding: Feign was using Ribbon as a LoadBalancer. Ribbon was configured in a properties file with different lists of hosts for all the applications clients.

My questions are:

  1. How am I supposed to use Spring Cloud LoadBalancer since I did not manage to find any comprehensible examples for me?
  2. Since I am using SpringCloudOpenFeign 3.0.6, which would be the suitable spring-cloud-starter-loadbalancer version? I have tried using 3.0.5( but I get a Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: @RequestMapping annotation not allowed on @FeignClient interfaces) and also 3.1.0 (and I get java.lang.ClassNotFoundException:org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties); did not find any related info for neither of the errors on google
skorpyo
  • 97
  • 1
  • 9

1 Answers1

4

You can find comprehensive documentation of Spring Cloud LoadBalancer, with all the details on how to set it up here. You can use it with Service Registry or, if you want to pass the list of hosts manually in properties, you can use SimpleDiscoveryClient You can also find a sample that uses Spring Cloud OpenFeign with Spring Cloud LoadBalancer here - the spring-cloud-starter-loadbalancer dependency is not in the pom, but gets included transitively via spring-cloud-starter-netflix-eureka-client. For more information about switching from Spring Cloud Netflix - based stack to the currently supported Spring Cloud stack, you can also watch this presentation recording.

Spring Cloud OpenFeign 3.0.5 works with Spring Cloud LoadBalancer 3.0.4, however, manually setting library versions for Spring Cloud is discouraged in general. You should use dependency management instead. You can find the setup at Spring Cloud projects landing page. Also, the easiest way to generate a correct build file for Spring Cloud Projects is to use start.spring.io.

OlgaMaciaszek
  • 3,662
  • 1
  • 28
  • 32
  • I have removed the ribbon dependencies and added the Spring Cloud LoadBalancer, configured SimpleDiscoveryClient properties (cloud:discovery:client:simple:instances:my-service[0]:uri: localhost:8070). At startup when I use the breakpoint in SimpleDiscoveryClient I can see that it manages to get it's instances using getInstances() but when it makes a call to one of the services I receive : "Method threw 'feign.RetryableException' exception." with message : "null executing GET http://my-service/app/v1/data". Did I miss to add anyhthing in my configurations ? – skorpyo Jan 14 '22 at 16:42
  • 1
    Finally managed to fix the problem. When configuring the hosts for Ribbon in the properties file they worked as host:7080 but it seems that for the cloud load balancer it does not work without specifying the protocol (PASS THE HOST as https ://host:7080). Thank you for the support Olga! – skorpyo Jan 16 '22 at 22:11
  • 3
    @skorpyo You can set scheme, like so: `spring.cloud.discovery.client.simple.instances.my-service[0].uri=https://localhost:8880` – OlgaMaciaszek Jan 18 '22 at 13:20