6

We're moving away from the spring-cloud Netflix OSS ecosystem one step at a time. Currently we're implementing spring-cloud-loadbalancer and removing Ribbon. However we used to have a lot of static services in our integration tests, now with the move from ribbon towards spring-cloud-loadbalancer those properties are not being picked up any longer. i.e.:

foo-service.ribbon.NIWSServerListClassName=com.netflix.loadbalancer.ConfigurationBasedServerList
foo-service.ribbon.listOfServers=localhost:9876

We've migrated towards using spring-cloud-loadbalancer in the following way
First we annotated our Webclient.Builder with @LoadBalanced like this

@Bean
@LoadBalanced
fun webClientBuilder() = WebClient.builder()

And then we've added the @LoadBalancerClient annotation on the client classes like this

@LoadBalancerClient(name = "foo-service", configuration = [FooServiceConfiguration::class])
class FooServiceClient(private val basicAuthWebClient: WebClient)

This results in our tests failing with an UnknownHostException for foo-service.

Now My question is how do we configure this static server list in the new spring-cloud-loadbalancer?

J.Pip
  • 4,523
  • 7
  • 31
  • 49
  • 2
    ribbon properties don't work for spring cloud loadbalancer. You can use `spring.cloud.discovery.client.simple.*` properties. See https://cloud.spring.io/spring-cloud-static/spring-cloud-commons/2.2.0.RELEASE/reference/html/appendix.html – spencergibb Jan 14 '20 at 17:01
  • @J.Pip Which property did you end up using from the ```spring.cloud.discovery.client.simple``` instead of the ```NIWSServerListClassName``` ? – Nayeem Oct 21 '21 at 20:13
  • Looks like the ribbon related configs like ```NIWSServerListClassName``` wont work with spring cloud – Nayeem Oct 26 '21 at 22:40

1 Answers1

4

Based on @spencergibb's comment, I guess something like this should work:

spring:
  cloud:
    discovery:
      client:
        simple:
          instances:
            foo-service:
              - instanceId: foo1
                serviceId: foo-service
                host: localhost
                port: 9876```
Mihaita Tinta
  • 219
  • 2
  • 6
  • What would be the instanceId here? – Nayeem Oct 24 '21 at 02:55
  • 1
    If you have multiple instances registered, each should have an unique value.: https://github.com/spring-cloud/spring-cloud-commons/blob/95ce58741d0506111a562fb7ec8de2c1a79c44b9/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java#L31 – Mihaita Tinta Oct 25 '21 at 11:07