Spring cloud load balancer with Spring Cloud gateway

2.3k views Asked by At

I have 4 Spring boot services up and running.

  1. the First service is an API gateway manager implemented using Spring cloud gateway.

The Yml file is as below:

server:
  port: 8080
 
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka  

spring:

  application:
      name: spring-cloud-gateway
   
  cloud:
    gateway:
      routes:
      - id: employeeModule
        uri: lb://FIRST-SERVICE
        predicates:
        - Path=/employee/**
        filters:
        - AddRequestHeader=first-request, first-request-header
        - AddResponseHeader=first-response, first-response-header
        - CustomFilter
      - id: consumerModule
        uri: lb://SECOND-SERVICE
        predicates:
        - Path=/consumer/**
        filters:
        - AddRequestHeader=second-request, second-request-header
        - AddResponseHeader=second-response, second-response-header
        - CustomFilter
  1. Eureka server implemented using Spring cloud netflix Eureka server. Maven dependency is spring-cloud-starter-netflix-eureka-server

  2. A micro service exposing a endpoint.

  3. Another micro service exposing another endpoint.

All(1,3,4) services register themselves to the Eureka server and I am able to route requests from the API gateway manager to the corresponding Microservice based on routing defined in the gateway manager.

All of the above is working fine. I would like to integrate Spring cloud Load balancer here so that once a request comes to the API gateway manager, it redirects to the available instances of a service.

I think I should be including load balancer dependency into API gateway manager but I am not sure how do I configure this in API gateway manager?

I would need as many load balancers as the number of different microservices I have?

0

There are 0 answers