Describe the bug
Going through the documentation at https://cloud.spring.io/spring-cloud-openfeign/reference/html/ it is mentioned ->
If you don’t want to use Eureka, you can simply configure a list of servers in your external configuration (see above for example)."
However, the link for the example is a dead link.
The document mentions that it recommends to set spring.cloud.loadbalancer.ribbon.enabled to false. However, I was not able to find any documentation to provide listOfServers manually without ribbon and for multiple clients.
I was able to find an example at https://spring.io/guides/gs/spring-cloud-loadbalancer/ on how to provide server list manually for spring-cloud-loadbalancer manually, and then was able to create the config as below.
@Bean
public ServiceInstanceListSupplier serviceOneInstanceSupplier(@Value("${service1.listOfServers}") List<String> serversList) {
String serviceId = "service1";
ServiceInstance[] instances = serversList.stream()
.map(server -> {
URI url;
try {
url = new URI(server);
} catch (URISyntaxException e) {
throw new ApplicationException(e);
}
return new DefaultServiceInstance(UUID.randomUUID().toString(), serviceId, url.getHost(), url.getPort(), url.getScheme().equals("https"));
}).collect(Collectors.toList()).toArray(new ServiceInstance[serversList.size()]);
return ServiceInstanceListSuppliers.from(serviceId, instances);
}
The above configuration worked.
However, now, we have the requirement to call another service with a different list of servers.
If we create another identical bean like below:
@Bean
public ServiceInstanceListSupplier serviceTwoInstanceSupplier(@Value("${service2.listOfServers}") List<String> serversList) {
String serviceId = "service2";
ServiceInstance[] instances = serversList.stream()
.map(server -> {
URI url;
try {
url = new URI(server);
} catch (URISyntaxException e) {
throw new ApplicationException(e);
}
return new DefaultServiceInstance(UUID.randomUUID().toString(), serviceId, url.getHost(), url.getPort(), url.getScheme().equals("https"));
}).collect(Collectors.toList()).toArray(new ServiceInstance[serversList.size()]);
return ServiceInstanceListSuppliers.from(serviceId, instances);
}
We get an exception saying that we cannot have duplicate bean of type ServiceInstanceListSupplier
Can you please help, if we have missed anything?
Comment From: OlgaMaciaszek
Hello @hviranicitco You can provide a list of servers through the configuration using SimpleDiscoveryClient. Will fix the link in the docs.
Comment From: hviranicitco
Hi @OlgaMaciaszek,
We use Eureka for connecting to our configuration server. So our requirement is to keep using Eureka for other services. Only for these services we want to configure it manually. Not sure, if this mixed approach works with SimpleDiscoveryClient option.
For now, we have enabled ribbon and using ribbon for load balancing.
Thanks for following up.
Comment From: OlgaMaciaszek
Yes, @hviranicitco, we use a CompositeDiscoveryClient that allows using together various implementations of DiscoveryClient found in the classpath that use the Ordered interface to establish priority.
Comment From: victor-matos
I believe we have a similar issue. We use @FeignClient with Eureka and Ribbon and it works just fine. We now want to use some of the FeignClient facilities to communicate with another application which is not part of Spring Cloud ecosystem and therefor is a little bit harder to registry on Eureka. This CompositeDiscoveryClient can do the trick when it comes to use two different set of Feign configuration? Thanks in advance!
Comment From: ghost
The new link is dead now too.
Comment From: rishits85
I tried using the compositeDiscoveryClient but it doesn't work since it says simpleDiscoveryClient is marked as primary. As an alternative, if I supply a list of servers in yaml for simpleDiscoveryClient to use, it does not allow me to set the endpoint as secure and by default uses http request (my server only accepts http requests). Any alternatives to this?