spring-cloud-loabalancer configuring static server list
Asked Answered
I

1

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?

Inning answered 14/1, 2020 at 12:58 Comment(3)
ribbon properties don't work for spring cloud loadbalancer. You can use spring.cloud.discovery.client.simple.* properties. See cloud.spring.io/spring-cloud-static/spring-cloud-commons/…Steady
@Inning Which property did you end up using from the spring.cloud.discovery.client.simple instead of the NIWSServerListClassName ?Corduroys
Looks like the ribbon related configs like NIWSServerListClassName wont work with spring cloudCorduroys
F
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```
Fauteuil answered 24/3, 2021 at 11:44 Comment(2)
What would be the instanceId here?Corduroys
If you have multiple instances registered, each should have an unique value.: github.com/spring-cloud/spring-cloud-commons/blob/…Fauteuil

© 2022 - 2024 — McMap. All rights reserved.