Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Spring Cloud Loadbalancer be used together with Netflix Eureka instead of Netflix Ribbon?

From the announcement of the Spring Cloud Greenwich release, see https://spring.io/blog/2019/01/23/spring-cloud-greenwich-release-is-now-available, I noticed that is recommended to replace Netflix Ribbon with Spring Cloud Loadbalancer.

Does that mean that Spring Cloud Loadbalancer can be use by a client to connect to services registered in Netflix Eureka without using Netflix Ribbon?

I have tried to find documentation and/or examples that describes how to do that, but I haven't find any.

like image 427
Magnus Larsson Avatar asked Oct 28 '22 19:10

Magnus Larsson


1 Answers

You can find a sample in the tests of Spring Cloud Loadbalancer. So what you'll have to do is the following. You'll have to annotate a configuration class with @LoadBalancerClient (or wrap it in @LoadBalancerClients if you want to have multiple clients) where you specify your client's name and its config class. In that load balancer client's config class you'll need to create a bean which will return a load balancer. In the test it's the RoundRobinLoadBalancer. You can then use that load balancer bean to pick the next service instance, which in turn can be used to make the call to your other service.

See this test: https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/LoadBalancerTest.java#L132

like image 106
TYsewyn Avatar answered Oct 31 '22 08:10

TYsewyn