Skip to Content
๐Ÿ“œ ์ „์ฒด ํ”„๋กœ์ ํŠธ๐Ÿงโ€โ™‚๏ธ MSA ์‚ฌ์ด๋“œ ํ”„๋กœ์ ํŠธ(SIDE PROJECT)

๐Ÿงโ€โ™‚๏ธ MSA ์‚ฌ์ด๋“œ ํ”„๋กœ์ ํŠธ(SIDE PROJECT)

๐Ÿ“… 2025.07 ~ 2025.08๐Ÿ‘ฅ 1๋ช…๐Ÿ›  Spring Boot ยท Spring Cloud ยท Eureka ยท Config ยท OpenFeign ยท Kafka ยท Docker๐ŸŽฏ ์„œ๋น„์Šค ๋ถ„๋ฆฌ/ํ†ต์‹  ์„ค๊ณ„

๐ŸŽฏ ํ”„๋กœ์ ํŠธ ๊ฐœ์š”

๋‹จ์ผ ์„œ๋ฒ„ ๊ตฌ์กฐ๋ฅผ ์„œ๋น„์Šค๋ณ„๋กœ ๋ถ„๋ฆฌํ•˜๊ณ  ํ†ต์‹ ํ•˜๋Š” MSA ๊ตฌ์กฐ๋กœ ์ „ํ™˜ํ•˜๋Š” ๊ฐœ์ธ ์‚ฌ์ด๋“œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค. Spring Cloud ํ•ต์‹ฌ ์ปดํฌ๋„ŒํŠธ(Eureka, Config, Gateway, Feign)๋ฅผ ์—ฐ๋™ํ•˜๊ณ  Docker๋กœ ๋ฉ€ํ‹ฐ ์„œ๋น„์Šค๋ฅผ ํ•จ๊ป˜ ๊ตฌ๋™ํ•˜๋„๋ก ๊ตฌ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ›  ๊ธฐ์ˆ  ์Šคํƒ

  • Spring Boot, Spring Cloud (Eureka, Config, Gateway, OpenFeign)
  • Kafka, Docker, WSL, Actuator

๐Ÿงฉ ๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ํ•™์Šต ํฌ์ธํŠธ

1. ์„œ๋น„์Šค ๋””์Šค์ปค๋ฒ„๋ฆฌ (Eureka)

  • ๊ฐ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๊ฐ€ Eureka ์„œ๋ฒ„์— ์ž๋™ ๋“ฑ๋ก๋˜๋„๋ก ์„ค์ •.
  • ์„œ๋น„์Šค ๊ฐ„ IP๋ฅผ ๊ณ ์ •ํ•˜์ง€ ์•Š์•„๋„ ์ž๋™ ํƒ์ƒ‰ ๊ฐ€๋Šฅํ•จ์„ ํ™•์ธ.
  • EUREKA_CLIENT๊ฐ€ ์„œ๋ฒ„ ์ƒํƒœ๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ๊ฐฑ์‹ ํ•˜๋ฉฐ ์žฅ์•  ๊ฐ์ง€ ๋™์ž‘์„ ์‹ค์Šตํ•จ.
eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8761/eureka/

ํ•™์Šต ํฌ์ธํŠธ:

์ˆ˜๋™ IP ์—ฐ๊ฒฐ์ด ํ•„์š” ์—†๋Š” ์„œ๋น„์Šค ์ž๋™ ํƒ์ƒ‰ ๊ตฌ์กฐ์˜ ์›๋ฆฌ๋ฅผ ์ดํ•ด.


2. ์ค‘์•™ ์„ค์ • ๊ด€๋ฆฌ (Config Server)

  • Config Server๋ฅผ ํ†ตํ•ด ๊ฐ ์„œ๋น„์Šค์˜ yml ํŒŒ์ผ์„ ์ค‘์•™ Git ์ €์žฅ์†Œ์—์„œ ๋ถˆ๋Ÿฌ์˜ด.
  • ์„œ๋น„์Šค๋ณ„ ์„ค์ •์ด ๋ณ€๊ฒฝ๋˜์–ด๋„, Config ์„œ๋ฒ„์˜ ์ €์žฅ์†Œ๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋จ.
  • ํ™˜๊ฒฝ ๋ณ€์ˆ˜(GIT_USERNAME, CONFIG_ENCRYPTION_KEY)๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์•ˆ๊ฐ’ ๊ด€๋ฆฌ ์‹ค์Šต.
set GIT_USERNAME=your_github_username # ๋ณด์•ˆ์„ ์œ„ํ•ด ์ž„์‹œ ์ž‘์„ฑํ•ด๋†“์€ ์œ ์ €๋„ค์ž„ set CONFIG_ENCRYPTION_KEY=my-super-secret-key

ํ•™์Šต ํฌ์ธํŠธ:

์‹ค์ œ ์šด์˜ ํ™˜๊ฒฝ์ฒ˜๋Ÿผ ์ค‘์•™ ์„ค์ • ๊ด€๋ฆฌ์™€ ๋ณด์•ˆ ๋ถ„๋ฆฌ์˜ ๊ฐœ๋…์„ ์ฒด๋“.


3. API Gateway ๋ผ์šฐํŒ…

  • ์™ธ๋ถ€ ์š”์ฒญ์ด http://localhost:8080/user-service/** ๋กœ ๋“ค์–ด์˜ค๋ฉด

    ๋‚ด๋ถ€์ ์œผ๋กœ User-Service๋กœ ๋ผ์šฐํŒ…๋˜๋„๋ก ์„ค์ •.

  • ๋ผ์šฐํŒ…, ํ•„ํ„ฐ, ๊ฒฝ๋กœ ๋ฆฌ๋ผ์ดํŠธ ๋“ฑ ๊ธฐ๋ณธ์ ์ธ Gateway ์„ค์ •์„ ์‹ค์Šต.

spring: cloud: gateway: routes: - id: user-service uri: http://localhost:8081/ predicates: - Path=/user-service/**

ํ•™์Šต ํฌ์ธํŠธ:

API ๊ฒŒ์ดํŠธ์›จ์ด์˜ ์—ญํ• (๋ณด์•ˆ, ํŠธ๋ž˜ํ”ฝ ์ œ์–ด, ๋ผ์šฐํŒ…)๊ณผ ๋ผ์šฐํŒ… ์„ค์ •์˜ ๊ธฐ๋ณธ ์›๋ฆฌ๋ฅผ ์ดํ•ด.


4. ์„œ๋น„์Šค ๊ฐ„ ํ†ต์‹  (Feign Client)

  • auth-service์™€ user-service ๊ฐ„ ํ†ต์‹ ์„ Feign Client๋กœ ๊ตฌํ˜„.
  • RESTTemplate์„ ๋Œ€์ฒดํ•˜์—ฌ, ์ธํ„ฐํŽ˜์ด์Šค ๊ธฐ๋ฐ˜ ํ†ต์‹  ๊ตฌ์กฐ๋ฅผ ๊ฒฝํ—˜.
@FeignClient(name = "auth-service") public interface AuthClient { @GetMapping("/auth/validate") String validate(@RequestParam String token); }

ํ•™์Šต ํฌ์ธํŠธ:

Feign์ด ๋‚ด๋ถ€์ ์œผ๋กœ HttpClient๋ฅผ ๋ž˜ํ•‘ํ•˜์—ฌ ๊ฐ„๊ฒฐํ•œ ์„œ๋น„์Šค ๊ฐ„ ํ˜ธ์ถœ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ ๋‹ค๋Š” ์ ์„ ์ดํ•ด.

๐Ÿ“Œ ์ฃผ์š” ๊ธฐ๋Šฅ

  • ์Šคํ”„๋ง cloud๋ฅผ ์‚ฌ์šฉํ•œ msa ์„œ๋น„์Šค
  • ์œ ์ €, ๊ธฐ๋Šฅ, api ์„œ๋ฒ„๋ฅผ ๋ถ„๋ฆฌํ•˜๊ณ  FeignClient๋ฅผ ์ด์šฉํ•จ์œผ๋กœ์จ ๊ฐ msa๊ฐ„์˜ ํ†ต์‹ ์„ ๊ตฌํ˜„

๐Ÿš€ ๋ฐฐ์šด ์ 

  • msa ์•„ํ‚คํ…์ณ์˜ ์„ค๊ณ„๋ฐฉ๋ฒ•
  • FeignClient๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹๊ณผ Config Server์˜ ์šด์˜๋ฐฉ๋ฒ•

๐Ÿ”— https://github.com/cvcvcx9/my-spring-microservice-repoย 

Last updated on