load balance with spring cloud gateway

Viewed 2849

I'm unable to figure from spring-cloud-gateway docs how to configure a load balancer. Some basic facts about my approach.

  1. Not Using eureka or ribbon. But planning to use ReactiveLoadBalancerClientFilter
  2. Using a combination of java-dsl and yaml filters

What I need help with is how to configure a lb:// scheme after a gateway filter(1st filter), so I can route request to multiple backend servers.

My 1st filter is:

public RouteLocator routes(RouteLocatorBuilder builder) {
builder.routes().route("rewrite_response_obj", r -> r
                        .asyncPredicate(serverWebExchange -> {
                            return Mono.just(serverWebExchange.getRequest().getURI().getPath().contains("mis2"));
                        })
                        .filters(f -> {
                                    return f.prefixPath("/")
                                            .modifyRequestBody(String.class, String.class, MediaType.APPLICATION_JSON_VALUE,
                                                    (exchange, s) -> Mono.just("2222222"));
                                }
                        )
                        .uri("lb://target-lb")) // How to configure target-lb 
                .build();
}

Spring docs have a lot of reference to use lb://xyz but I cant find where they have configured it?

I tried:

spring:
  cloud:
      loadbalancer:
        ribbon:
          enabled: false
        instances:
          - name: target-lb
            servers: http://localhost:8800

But it says:

2021-03-03 18:49:42.507 WARN 55243 --- [ctor-http-nio-3] o.s.c.l.core.RoundRobinLoadBalancer : No servers available for service: target-lb

Libs in my class-path:

spring-cloud-starter-loadbalancer
spring-cloud-starter-gateway
0 Answers
Related