4

Trying to get spring cloud gateway to load balance across a couple of instances of our application, but just can't figure it out. We don't have a service registry at present (no Eureka etc).

I've been trying to use ribbon and have a configuration like so:

spring:
  application:
    name: gateway-service  
  cloud:
    discovery:
        locator:
          enabled: true
    gateway:
      routes:
      - id: my-service
        uri: lb://my-load-balanced-service
        predicates:
        - Path=/
        filters:
        - TestFilter
ribbon:
  eureka:
   enabled: false
my-load-balanced-service:
  ribbon:
    listOfServers: localhost:8080, localhost:8081

However when I try a request to the gateway, I get a 200 response with content-length 0, and my stubs have not been hit.

I have a very basic setup, no beans defined.

How can I get ribbon to play nice / or an alternative?

Alex
  • 587
  • 11
  • 31
  • Are you able to get load-balancing working with Spring Cloud Gateway and Ribbon. We also have similar requirement's when we need to configure multiple target's for the proxies exposed via spring cloud gateway – shatk Sep 15 '19 at 12:44
  • @shatk yup, all I was doing wrong was not including the dependency included in the accepted answer – Alex Sep 18 '19 at 20:04
  • With above configuration will ribbon load balancing work if one of the instance is down ? Is the health of the service verified before forwarding the request to the target ? – shatk Dec 08 '19 at 11:13
  • 1
    1. Yes 2. Not with this setup - You need to wire in an implementation of IPing to tell ribbon how to verify the health of your instances. See here: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-ribbon.html – Alex Jan 13 '20 at 08:59

1 Answers1

4

You should check out whether spring-cloud-starter-netflix-ribbon dependency is on your project or not

李字符
  • 56
  • 2
  • Yup that was the solution. Ribbon classes are present without but requires this starter to get it working. – Alex Mar 07 '19 at 15:33
  • How does it load balance the request or how it performs client side load balancing? – PAA Aug 28 '21 at 12:29