Api Gateway Service 와 Discovery Service를 연결하고
Discovery Service와 First Service, Second Service를 연결하는 과정입니다.
따라서 Discovery Service에는 Api Gateway, First Service, Second Service 3개의 URL 맵핑정보를 관리하고 있습니다.
API Gateway Service에 디펜더시 추가 ( Eureka Client )
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
1. apigateway-service 프로젝트 < application.yml >
2. first-service 프로젝트 < application.yml >
3. second-service 프로젝트 < application.yml >
위 3개의 프로젝트에 eureka Discovery Service URL로 설정정보 true로 변경 및 설정
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
기동 순서!!
1. Eureka Server ( discovery service )
2. API Gateway Server ( apigateway-service )
3. First Server, Second Server ( front-service, second-service )
Eureka Server ( discovery service )에 3개의 서버가 등록되어있는지 확인해보자!
http://localhost:8761/
Instances currently registered with Eureka에 3개의 서버가 등록되어있다.
API Gateway의 라우팅 정보를 변경해보자
apigateway-service < application.yml >
spring.cloud.gateway.routes.uri 변경
Eureka에 등록한 First Service, Second Service의 Application 이름을 설정하면된다.
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: lb://MY-FIRST-SERVICE
predicates:
- Path=/first-service/**
filters:
# - AddRequestHeader=first-request, first-request-header2
# - AddResponseHeader=first-response, first-response-header2
- CustomFilter
- id: second-service
uri: lb://MY-SECOND-SERVICE
predicates:
- Path=/second-service/**
filters:
# - AddRequestHeader=second-request, second-request-header2
# - AddResponseHeader=second-response, second-response-header2
- name: CustomFilter
- name: LoggingFilter
args:
baseMessage: Hi, there
preLogger: true
postLogger: true
apigateway로 first-service가 정상 요청되는지 확인!
http://localhost:8000/first-service/welcome
SpringBoot MSA (10) - MicroService / UserService H2 연결 (1) (2) | 2023.10.16 |
---|---|
SpringBoot MSA (9) - Spring Cloud Gateway / Load Balancer (0) | 2023.10.10 |
SpringBoot MSA (7) - API Gateway Service Filter (2) (0) | 2023.10.10 |
SpringBoot MSA (6) - API Gateway Service Filter (1) | 2023.10.09 |
SpringBoot MSA (5) - API Gateway Service (0) | 2023.10.03 |
댓글 영역