Spring Cloud - 7. Load Balancer 적용

Spring Cloud로 개발하는 마이크로서비스 애플리케이션 7 - Load Balancer 적용

Spring Cloud Gateway와 Eureka연동

Gateway 설정

eureka 설정하기

eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka

Gateway 설정하기

spring:
application:
name: apigateway-service
cloud:
gateway:
default-filters:
- name: GlobalFilter
args:
baseMessage: Spring Cloud Gateway Global Filter
preLogger: true
postLogger: true

routes:
- id: first-service
# uri: http://localhost:8081/
uri: lb://MY-FIRST-SERVICE
predicates:
- Path=/first-service/**
filters:
- CustomFilter
# - AddRequestHeader=first-request, first-request-header2
# - AddResponseHeader=first-response, first-response-header2
- id: second-service
# uri: http://localhost:8082/
uri: lb://MY-SECOND-SERVICE
predicates:
- Path=/second-service/**
filters:
- name: CustomFilter
- name: LoggingFilter
args:
baseMessage: Hi, there.
preLogger: true
postLogger: true
# - AddRequestHeader=second-request, second-request-header2
# - AddResponseHeader=second-response, second-response-header2

Client 설정

first-service

server:
port: 8081
spring:
application:
name: my-first-service

eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka

second-service

server:
port: 8082
spring:
application:
name: my-second-service

eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
Share