I’m struggling to get client-side load balancing configured with
spring-cloud-starter-loadbalancer
which is in my pom.xml.
I want to make this feign client load balanced:
//@LoadBalancerClient(name = "eisec2", configuration = LoadBalancerConfiguration.class)
@FeignClient(name = "eisec2")
public interface Eisec2Client {
@RequestMapping(path = "CallDetails/{number}", method = RequestMethod.GET)
CallDetails getCaller(String cli);
@RequestMapping(path = "Status", method = RequestMethod.GET)
CallDetails getStatus();
}
with enabled feign clients and some default configuration for client load balancing:
@EnableFeignClients
@SpringBootApplication
@LoadBalancerClients(defaultConfiguration = LoadBalancerClientConfiguration.class)
public class IsecServerApplication {
...psvm...
}
then in application.properties I have:1
spring.cloud.loadbalancer.enabled=true
spring.cloud.discovery.client.simple.instances.eisec2[0].uri=http://ip:6090/eisec/1
spring.cloud.discovery.client.simple.instances.eisec2[1].uri=http://ip:6091/eisec/1
spring.cloud.loadbalancer.ribbon.enabled=false
this is the class that I have commented out on the feign client declaration:
public class LoadBalancerConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}
@Bean
public ServiceInstanceListSupplier instanceSupplier(ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder()
.withBlockingDiscoveryClient()
.withHealthChecks()
.build(context);
}
}
all I read is that it cannot have an @Configuration stereotype on it.
However, it’s not enough, the injected Eisec2Client
is of type HardCodedTarget
and ‘url’ property of http://eisec2
which is wrong so it does request on non existing uri.
I was unable to find single complete example of code for spring-cloud-starter-loadbalancer
with spring-cloud-starter-openfeign
I’ll appreciate some working example if somebody has it or instructions on how to achieve this (at least simple client side loadbalance)
I am on spring-cloud version: 2023.0.1
and
spring-boot-parent version 3.2.6.