Change Configuration from Ribbon to Spring Cloud Load Balancer in spring cloud gateway

3.6k views Asked by At

I have below configuration for spring cloud gateway with ribbon

server:
  port: 8080

spring:
  cloud:
    gateway:
      routes:
        - id: UserModule
          uri: lb://load-balanced-service-user
          predicates:
            - Path=/api/user/**
ribbon:
  eureka:
    enabled: false
Load-balanced-service-user:
  ribbon:
    listOfServers: localhost:9999,localhost:8888

Now i want to remove Ribbon and replace with spring cloud load balancer .

I added

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>

Now what other configuration i need to add in my application.yaml file to switch to spring cloud load balancer ? I want to add configuration on .yaml file .I do not want to break old structure with ribbon that is configured in .yaml file .

1

There are 1 answers

4
OlgaMaciaszek On

If you are using the Hoxton release train, you will need to set spring.cloud.loadbalancer.ribbon.enabled to false. From what I see, you are using a static list of servers instead of a service registry. In LoadBalancer, you can achieve that by adding a properties-backed SimpleDiscoveryClient. Note that to reproduce the Ribbon's health-check behaviour for such static instances, we recommend the use of the Instance Health Check mechanism and disabling loadbalancer caching, since an alternative caching mechanism is provided with the Instance Health check mechanism.