Spring Cloud - 11. Users Microservice Gateway 연동

목차

Users Microservice Gateway 연동

@GetMapping("/health_check")
public String status(){
return String.format("It's Working in User Service on PORT %s", env.getProperty("local.server.port"));
}
server:
port: 8080

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

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

routes:
- id: user-service
# uri: http://localhost:8081/
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/**
filters:
- CustomFilter
# - AddRequestHeader=first-request, first-request-header2
# - AddResponseHeader=first-response, first-response-header2

- 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

Gateway를 거처 User Service에 접근하게 되면 문제가 발생

  • User Service의 URI와 API Gateway의 URI가 다르기 때문에 문제가 생김
@GetMapping("/user-service/health_check")
public String status(){
return String.format("It's Working in User Service on PORT %s", env.getProperty("local.server.port"));
}
Share