Debugging Sparrow

API Gateway with Zuul 2.0 (1)

2018/08/25 Zuul API Gateway Netflix 게이트웨이

Zuul 2.0

Zuul은 Netflix에서 사용 / 공개한 API Gateway 서비스입니다. MSA에서 많은 기여를 하고 있는 회사답게 Zuul 또한 MSA에서 요구되는 기능을 위한 컴포넌트들이 많이 있습니다.

Netflix는 왜 Zuul을 만들었는가

zuul-physical-arch.png

Zuul은 Netflix를 운영하면서 발생하는 Network API traffic 이슈들에 대응하기 위해서 만들어졌습니다. 기본적으로 Groovy 언어로 작성한 다양한 필터들을 이용해서 API의 끝단에 기능들을 발 빠르게 적용할 수 있습니다.

Zuul의 기능들

Zuul에서 제공하는 핵심 기능들 입니다.

  • 인증과 보안(Authentication and Security)
  • 모니터링(Insights and Monitoring)
  • 동적 라우팅(Dynamic Routing)
  • Stress Testing
  • Load Shedding
  • 정적 응답 처리(Static Response handling)
  • Multiregion Resiliency

Zuul 2.0 실습

소스코드 복사 및 빌드

1
2
3
$ git clone git@github.com:Netflix/zuul.git
$ cd zuul/
$ ./gradlew build

빌드는 생각보다 오래 걸립니다. 이때 물을 한 잔 마시면 좋습니다.

실행

1
$ ./gradlew run

샘플 앱이 실행되야 하는데 90%에서 더 넘어 가질 않습니다. 시작부터 말썽이네요.

1
2
3
2018-08-25 10:56:20,168 WARN  com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient [main] Request execution failed with message: org.apache.http.conn.ConnectTimeoutException: Connect to ec2-50-19-255-39.compute-1.amazonaws.com:7001 timed out
2018-08-25 10:56:25,175 ERROR com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient [main] Request execution error
com.sun.jersey.api.client.ClientHandlerException: org.apache.http.conn.ConnectTimeoutException: Connect to ec2-50-17-247-232.compute-1.amazonaws.com:7001 timed out

와 같은 에러입니다. sample앱의 기본 세팅이 Eureka를 사용하고 Netflix의 서버들을 사용하도록 되어있기 때문인데요.

Eureka는 다음에 알아보도록 하고 Eureka에서 서비스 리스트를 가져오지 않도록 옵션을 변경해 봅시다.
아래 경로에 기본 세팅 파일이 있습니다.
zuul-sample/src/main/resources/application.properties

1
2
3
4
5
6
7
8
9
10
-eureka.shouldUseDns=true
-eureka.eurekaServer.context=discovery/v2
-eureka.eurekaServer.domainName=discovery${environment}.netflix.net
-eureka.eurekaServer.gzipContent=true
-eureka.serviceUrl.default=http://${region}.${eureka.eurekaServer.domainName}:7001/${eureka.eurekaServer.context}
-api.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList

+eureka.shouldFetchRegistry=false
+api.ribbon.listOfServers=localhost:8080
+api.ribbon.client.NIWSServerListClassName=com.netflix.loadbalancer.ConfigurationBasedServerList

기존 eureka 관련 옵션들을 지우고 옵션을 추가해줍니다.

다시 서버를 실행해 보면 Output에 아래 내용이 추가된 것을 보실 수 있습니다. 실행이 됐습니다!
Zuul Sample: finished startup. Duration = 2809 ms
Zuul의 기본 port는 7001입니다. 브라우저를 열고 localhost:7001로 접근해 봅시다. 502error가 나고 terminal에는 Connection refused: localhost/127.0.0.1:8080와 같은 에러가 납니다.

8080 port에 Service가 없어서 그렇습니다. 자신이 가지고 있는 서버 프로젝트 하나를 8080으로 띄워봅시다. 다들 집에 이런 거 하나씩 있잖아요? 없다면 api.ribbon.listOfServers에 자신이 알고 있는 domain 아무거나 넣어서 해봅시다.

그리고 다시 7001 port로 접속해보면 어떤가요? 8080 port로 띄운 서버에 정상적으로 접근이 됩니다.

다음 시간에는 filter에 대해서 알아봅니다.

참고: https://github.com/Netflix/zuul/wiki

Author: dbgsprw

Link: https://dbgsprw.github.io/2018/08/25/zuul/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
API Gateway with Zuul 2.0 (2)
NextPost >
Golang 지역 변수의 주소 리턴
CATALOG
  1. 1. Zuul 2.0
    1. 1.1. Netflix는 왜 Zuul을 만들었는가
    2. 1.2. Zuul의 기능들
  2. 2. Zuul 2.0 실습
    1. 2.0.1. 소스코드 복사 및 빌드
    2. 2.0.2. 실행