3

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 .

abishkar bhattarai
  • 7,371
  • 8
  • 49
  • 66

1 Answers1

5

If you are using the Hoxton release train, you will need to set spring.cloud.loadbarancer.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.

OlgaMaciaszek
  • 3,662
  • 1
  • 28
  • 32
  • 2
    Thank you for this answer as it helps a lot. In case anyone is stuck on this, I wrote up a prototype for the load balancing without ribbon and service registry [https://github.com/yoonghan/springcloud-gateway]. Welcome for feedbacks and improvements. – Han Nov 11 '20 at 05:25
  • Is this also valid for version `2021.0.0`? – Peter Penzov Jan 23 '22 at 15:37