티스토리 뷰

API GateWay란?

MSA에서 언급되는 컴포넌트 중 하나이며, 모든 클라이언트 요청에 대한 end point를 통합하는 서버이다

그리고 인증 및 권한, 모니터링, logging 등 추가적인 기능 또한 수행한다

 

Zuul이란?

모든 마이크로서비스에 대한 요청을 받아들이고 라우팅하는 프록시 API GateWay 기능을 수행하는 라이브러리

 

  • 클라이언트(FrontEnd)와 서버(BackEnd) 사이의 출입문 역할
  • 주로 라우팅 기능을 담당
  • 횡단 관심사처리에 유리 - 모든 부분에서 필요로 하는 일들(보안, 인증 등)
  • Zuul의 모든 api 요청은 HystrixCommand로 구성되어 전달된다
  • api요청이 들어오면 전달 서버를 Eureka server에서 찾아 ribbon을 통해 로드밸런싱 수행하여 요청을 실행한다

Zuul 프로젝트 생성하기

 

1. GateWay로 사용될 Zuul 프로젝트 생성 

 

라이브러리 의존성 추가

dependencies {
compile('org.springframework.retry:spring-retry:1.2.2.RELEASE')
compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul)
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

}
  • Zuul 서비스 또한 Eureka Client임을 알고있어야 한다

application.yml 설정

spring:
  application:
    name: zuul

server:
  port: 8765

zuul:
  routes:
    product:
      path: /products/**
      serviceId: product
      stripPrefix: false
    display:
      path: /displays/**
      serviceId: display
      stripPrefix: false
eureka:
  instance:
    non-secure-port: ${server.port}
    prefer-ip-address: true
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  • 라우터들을 추가
    • servicedId : Eureka 서버에 저장된 서비스 아이디 명시
    • stripPrefix : false로 설정하면 Routing되어 넘어갈 때 path에 products가 붙어 넘어간다 
  • Zuul 서버 또한 Eureka Registery에 등록하기 위한 설정을 추가한다

메인클래스에 어노테이션 추가

@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulApplication.class, args);
    }
}
  • @EnableDiscoveryClient 대신 @EnableEurekaClient 사용해도 됌

참고 블로그

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함