Spring eureka
๊ณต์๋ฌธ์๊ฐ ์๊ฐ๋ณด๋ค ๋ชจ๋ ๋ด์ฉ์ ๋ค๋ฃจ๋ ๊ฒ ๊ฐ์ง๋ ์๋ค.
eureka ์ ๋ํด์ ์์๋ณด๊ธฐ ์ ์ Service discovery ์ ํ์์ฑ์ด๋ ๊ฐ๋ ์ ๋จผ์ ์์์ผ ํ๋ค. ์๋ ํฌ์คํ ์ ๋งค์ฐ ์ ์ ๋ฆฌ๊ฐ ๋์ด ์๋ค.d
Service Discovery ์ ํ์์ฑ์ ๋ํด์ ์์ฝํ์๋ฉด ์๋์ ๊ทธ๋ฆผ์ผ๋ก ์ค๋ช ํ ์ ์๋ค.

์์ ๊ณผ๋ ๋ค๋ฅด๊ฒ ์ค๋๋ ์ cloud-based MSA ์์๋ ์์ ๊ฐ์ด service instance ๋ค์ด network location ์ ๋์ ์ผ๋ก ํ ๋น๋ฐ๊ฒ ๋๋ค. ์๋ํ๋ฉด autoscaling ์ด ๋ฐ์ํ๊ธฐ ๋๋ฌธ์ด๋ค. ๊ฒฐ๊ณผ์ ์ผ๋ก client ๊ฐ ์ด๋๋ก ํต์ ํด์ผํ ์ง ๋ชจ๋ฅด๋ ์ํฉ์ด ๋ฐ์ํ ์ ์๋ค. ์ด ๋ service instance ๋ค์ network location์ ํ์ ํ๋ ํ์๋ฅผ service discovery ๋ผ๊ณ ํ ์ ์๋ค.
์ ํฌ์คํ ์์๋ service discovery pattern ์ผ๋ก client side, server side ๋ ๊ฐ์ง๋ฅผ ์ค๋ช ํ๊ณ ์๋ค.
Client-Side Discovery Pattern
client side ๋ client ๊ฐ ๋ก๋๋ฐธ๋ฐ์ฑ์ ์ฑ ์์ ๊ฐ๊ณ ์๋ ํํ์ด๋ค. service instance๋ค์ด registry ์ ๋ฑ๋กํ๋ ๊ฒ์ ๋ง๋๋ฐ ์ฌ๊ธฐ์ client ๊ฐ registry ์ ์ง์ํ ํ ์์์ ๋ก๋๋ฐธ๋ฐ์ฑ ํ๋จ์ ํด์ผํ๋ ๊ฒ์ด๋ค. Netflix OSS ๊ฐ ๋ํ์ ์ธ client side discovery pattern ์ด๋ผ๊ณ ํ๋ค.

Server-Side Discovery Pattern

๋ฐ๋ฉด์ server side discovery pattern์ client ์ ์์ฒญ์ด service ๋ฅผ ์ง์ ํฅํ์ง ์๊ณ ๋ก๋๋ฐธ๋ฐ์๋ฅผ ํฅํ๋ค. ์ฆ, ์์ฒญ์ ๋ก๋๋ฐธ๋ฐ์๋ฅผ ํตํด์ ํ๊ฒ ๋๋ค.
AWS ELB๊ฐ server side discovery pattern์ ์์๋ผ๊ณ ํ๋ค.
The AWS Elastic Load Balancer (ELB) is an example of a server-side discovery router. An ELB is commonly used to load balance external traffic from the Internet. However, you can also use an ELB to load balance traffic that is internal to a virtual private cloud (VPC). A client makes requests (HTTP or TCP) via the ELB using its DNS name. The ELB load balances the traffic among a set of registered Elastic Compute Cloud (EC2) instances or EC2 Container Service (ECS) containers. There isnโt a separate service registry. Instead, EC2 instances and ECS containers are registered with the ELB itself.
Self-Registration Pattern

์์์ ๋ค๋ค๋ฏ์ด client side๋ server side๋ instance ๊ฐ Service Registry ์ ๋ฑ๋ก์ ํ๋ค๋ ์ฌ์ค์ ๋ณํจ์ด ์๋ค. ์ด ๋ ๋ฑ๋ก์ ์ด๋ค์์ผ๋ก ํ๋์ง์ ๋ํ ๊ฒ์ Self-Registration ์ด๋ผ๋ ๊ฐ๋ ์ผ๋ก ์ค๋ช ํ๊ณ ์๋ค.
๋ด๊ฐ eureka๋ฅผ ๋ณด๋ฉด์ ๊ฐ์ฅ ๊ถ๊ธํ๊ณ ํท๊ฐ๋ ธ๋ ๋ถ๋ถ๋ ์ด ๋ถ๋ถ์ด๋ค. ๋จ์ง MSA์์ ์ฌ๋ฌ instance ๋ค์ ์ธํ๋ผ ์ ๋ณด(์์น ๋ฑ) ์ ํ ๊ณณ์ผ๋ก ๋ชจ์๋ค ์ ๋๋ก๋ง ์๊ณ ์์๊ณ , ๋๋ ์ธ๋ถ์ ์ผ๋ก ์ด๋ค ๋ฐฉ์์ผ๋ก ๋ฌด์์ ๋ชจ์ผ๋์ง๋ฅผ ์๊ณ ์ฐ๊ณ ์ถ์๋๋ฐ ๊ณต์ ๋ฌธ์์์ ๋ด๊ฐ ๋ชป์ฐพ์ ๊ฑด์ง ๋๋ฌด์ง ์ฐพ์ ์ ์์๋ค.
๊ฒฐ๊ตญ client์ registry ๋ชจ๋๋ฅผ ์ผ๋๊ณ ๋๋ค ๋ก๊ทธ ๋ ๋ฒจ์ root debug๋ก ๋๊ณ ๋ก๊ทธ๋ฅผ ํตํด์ ๋ญ ํ๋์ง ์ ์ ์์๋๋ฐ ์ด ํฌ์คํ ์์ ๊ทธ ์ฌ์ค์ ๋งค์ฐ ์ ํํ๊ฒ ์ค๋ช ํด์ฃผ๊ณ ์๋ค.
When using the selfโregistration pattern, a service instance is responsible for registering and deregistering itself with the service registry. Also, if required, a service instance sends heartbeat requests to prevent its registration from expiring. The following diagram shows the structure of this pattern.
์ ๊ทธ๋ฆผ๊ณผ ์ ์ค๋ช ์ ๋์์๋ฏ์ด service instance๊ฐ ๋ฑ๋ก์ ์ฑ ์์ ๊ฐ๊ณ ์๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฑ๋ก์ ํ๋ค ์ผ์ ํ๊ฒ heartbeat์ ๋ณด๋ด์ regitstry ์์ ์ฌ๋ผ์ง๋ ๊ฒ์ ๋ฐฉ์งํ๋ค. ๊ฐ์ ๋งฅ๋ฝ์์ registry ๋ ์ผ์ ๊ธฐ๊ฐ ์์กด์ ๊ณ ๋ฅผ ํ์ง ์๋ instance ๋ ์ฃฝ์๋ค๊ณ ํ๋จํ๊ณ instance ์ ๋ณด์์ ์ญ์ ํ๋ค. ๊ทธ๋ฆผ์์ unregister() ๊ฐ ์๋๋ฐ, service instance๊ฐ ๋ด๋ ค๊ฐ๋ '๋ ์ฃฝ๋๋ค' ๋ผ๊ณ ์ ๊ณ ๊น์ง ํ๋ค. ๋ ๊ทธ๋ฆผ์์ ๋์ค์ง ์์๋๋ฐ eureka client๋ registry ์ ๋ฑ๋ก๋ ๋ชจ๋ ๋ค๋ฅธ instance ์ ๋ณด๋ค๋ ๊ฐ์ ธ๊ฐ๋ค.
์ ๋ฆฌํ์๋ฉด eureka ๊ธฐ์ค์ผ๋ก instance ๊ฐ ํ๋ ํ์๋ฅผ ๋ชฉ๋กํ ํ๋ฉด ์๋์ ๊ฐ๋ค.
register(1ํ)
heartbeat(์ง์์ ์ผ๋ก)
fetch(registry ์ ๋ฑ๋ก๋ ๋ค๋ฅธ app๋ค์ ์ ๋ณด(์ต์ด 1ํ ์ดํ delta ๋ก ๋ณํ๋ง ๋ฐ์๊ฐ))
unregister(1ํ)
์ด๋ฅผ eureka ๋ก๊ทธ์์ ๋ณด๋ฉด ์๋์ ๊ฐ๋ค. ๋ก๊ทธ๋ ๋ชจ๋ service registry ์์ ๊ธฐ๋ก๋ ๊ฒ์ด๋ค.
1. register ([POST /eureka/apps/SAMPLE-APP)
body ์๋ ์๋์ ๊ฐ์ ๋ด์ฉ์ด ๋ค์ด๊ฐ๋ค.
2. heartbeat(PUT /eureka/apps/SAMPLE-APP/192.168.35.111:sample-app:8070?status=UP&lastDirtyTimestamp=1656817373767)
3. fetch
4. unregister
eureka service registry ๋ฐ client ์ค์ ์ ์ ๋ฆฌ๋ ํฌ์คํ ๋ ๋ง๊ฑฐ๋์ ๊ณต์๋ฌธ์๋ง ๋ณด๊ณ ๋ฐ๋ผ๊ฐ๋ฉด ์ถฉ๋ถํ ์ฒ๋ฆฌํ ์ ์์ด์ ์ ๋ฆฌ๋ฅผ ์๋ตํ๋ค.
Last updated