BackEnd/Spring Cloud

์ด์ „ ํฌ์ŠคํŒ…์—์„  Webclient๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋น„์Šค๋“ค๊ฐ„์˜ ํ†ต์‹ ์„ ๊ตฌ์ถ•ํ–ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” Kafka๋ฅผ ํ†ตํ•ด์„œ ๋ฉ”์„ธ์ง€ ํ๋ฅผ ๊ธฐ์šฉํ•˜์—ฌ ์„œ๋น„์Šค๋“ค ๊ฐ„์˜ ํ†ต์‹  ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. kafka์— ๋Œ€ํ•œ ์˜ˆ์ „ ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ•ด์„œ ๊ตฌ์ถ•ํ–ˆ๋‹ค. ํ˜„์žฌ ๋‚ด ์„œ๋น„์Šค๋Š” app-service ์™€ user-service๊ฐ€ ์žˆ๋Š”๋ฐ, app-service๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ์ž์‹ ์˜ ์•ฑ์„ ์„œ๋ฒ„์— ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด ๋†“์•˜๋‹ค. ํ•„์ž๋Š” ์ง€๊ธˆ ์‚ฌ์šฉ์ž๊ฐ€ ์•ฑ์„ ๋“ฑ๋กํ•  ๋•Œ, User ์—”ํ‹ฐํ‹ฐ์— ์žˆ๋Š” appCount๋ฅผ +1ํ•ด์ฃผ๋Š” ์„œ๋น„์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. 0. Depdency ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด kafka๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. dependencies { implementation 'org.springframework.kafka:spring-..
Spring Cloud์— ๋Œ€ํ•œ ์„ค์ •์„ ์–ด๋Š์ •๋„ ๋งˆ์ณค๋‹ค. ์ด์ œ ๊ฐ ์„œ๋น„์Šค๋“ค ๊ฐ„์˜ ํ†ต์‹  ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. 0. WebClient Spring Boot์—์„œ๋Š” ์—ฌ๋Ÿฌ HTTP ํ†ต์‹  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค. ๋‚ด๊ฐ€ ์˜›๋‚ ์— ๋งŽ์ด ๋ดค๋˜ ํด๋ž˜์Šค๋Š” RestTemplate์ด์—ˆ๋‹ค. Spring Doc์—์„œ๋„ WebClient๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ๊ณ ํ•˜๊ณ  ์žˆ๊ณ , RestTemplate๋ณด๋‹ค ๋” ๋งŽ์€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— WebClient๋กœ ์ง„ํ–‰ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. 1. ๋™๊ธฐ vs ๋น„๋™๊ธฐ / Blocking vs Non-Blocking ๋จผ์ € ๋™๊ธฐ์™€ ๋น„๋™๊ธฐ๋ฅผ ๊ตฌ๋ถ„ํ•ด๋ณด์ž. - ๋™๊ธฐ(Synchronous) : ์š”์ฒญ ํ›„ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•  ๋•Œ ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆผ - ๋น„๋™๊ธฐ(Asynchronous) : ์š”์ฒญ ํ›„ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•  ๋•Œ ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š์Œ ๊ทธ๋ ‡๋‹ค๋ฉด,..
์ €๋ฒˆ ํฌ์ŠคํŒ…์—์„  ์ž„์‹œ๋กœ Public Repository๋ฅผ ์‚ฌ์šฉํ–ˆ์ง€๋งŒ, ์ค‘์š”ํ•œ ํŒŒ์ผ์ด ๋“ค์–ด์žˆ๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋Š” ๋‹น์—ฐํžˆ private์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿผ ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„ , Config Server์—์„œ private repository๋กœ๋ถ€ํ„ฐ ์„ค์ • ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ์„ธํŒ…ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค. 1. ๋น„๋Œ€์นญ ํ‚ค ์ƒ์„ฑ ๋งฅ์—์„œ๋Š” ssh ๋น„๋Œ€์นญ ํ‚ค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. $ ssh-keygen -m PEM -t rsa -b 4096 -C {๊นƒํ—ˆ๋ธŒ ๊ณ„์ •} ์ €์žฅํ•  ์œ„์น˜์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ(passphrase)๋ฅผ ์„ค์ •ํ•˜๊ณ  ๋งŒ๋“ค์–ด์ฃผ์ž. 2. Deploy Key ๋“ฑ๋ก ๋งŒ๋“ค์–ด ์ฃผ๋ฉด, .pub ์˜ Public key๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด๋ฅผ ๊ฐ€์ ธ์˜ค๋ ค๋Š” Private repository์— Deploy Key๋กœ ..
0. Spring Cloud Bus ์ง€๋‚œ ํฌ์ŠคํŒ…์—์„  Actuator๋ฅผ ์ด์šฉํ•ด์„œ refresh๋ฅผ ํ†ตํ•ด configuration ์ •๋ณด๋“ค์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด์•˜๋‹ค. ์ด ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์„ค์ • ์ •๋ณด๊ฐ€ ๋ฐ”๋€”๋•Œ ๋งˆ๋‹ค refresh๋ฅผ ํ•ด์ค˜์•ผ ํ•˜๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์‚ดํŽด๋ณด์ž. https://spring.io/projects/spring-cloud-bus/ Spring Cloud Bus Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or o..
0. Spring Cloud Config Server MSA์™€ ๊ฐ™์€ ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ ๊ฐ ์„œ๋ฒ„๋“ค์˜ ๊ตฌ์„ฑ์— ํ•„์š”ํ•œ ์„ค์ •๋“ค์„ ์™ธ๋ถ€ ์‹œ์Šคํ…œ์—์„œ ํ•œ๋ฒˆ์— ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. Spring Boot ๊ฐ™์€ ๊ฒฝ์šฐ๋Š”, ์„ค์ • ํŒŒ์ผ์ธ application.yml ๋˜๋Š” propertiesํŒŒ์ผ์ด ๊ทธ ๋Œ€์ƒ์ด ๋˜๊ฒ ๋‹ค. Spring Cloud์˜ Config Server๋ฅผ ๊ธฐ๋™ํ•˜์—ฌ ์„ค์ • ํŒŒ์ผ๋“ค์„ ํ•œ๊บผ๋ฒˆ์— ๋ฌถ์–ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ํ•œ ์ €์žฅ์†Œ์—์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ณ , ์„ค์ • ์ •๋ณด๋ฅผ ๋ฐ”๊พธ๋”๋ผ๋„ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋“ค์„ ๋‹ค์‹œ ๋นŒ๋“œํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. ์„œ๋น„์Šค๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ๊ฒฝ์šฐ, DEV์„œ๋ฒ„์™€ PROD ์„œ๋ฒ„๋ฅผ ๋ถ„๋ฆฌํ•ด์„œ ๊ฐœ๋ฐœํ•˜๊ธฐ๋„ ํ•˜๋Š”๋ฐ, ๊ฐ ์„œ๋ฒ„๋“ค ๋งˆ๋‹ค ์‚ฌ์šฉํ•˜๋Š” ์„ค์ • ์ •๋ณด๊ฐ€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์„œ๋ฒ„์— ๋งž์ถฐ์„œ ๊ธฐ๋™ํ•  ์ˆ˜ ์žˆ๊ฒ ๋‹ค. 1. Actuator ์•ž์—์„œ Config Server..
์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ๋Š” Eureka Server์™€ Microservice๋“ค์„ ๋“ฑ๋กํ•˜๋Š” ์„ค์ •์„ ์•Œ์•„๋ณด์•˜๋‹ค. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š”, Eureka Server์— ๋“ฑ๋ก๋œ ์„œ๋น„์Šค๋“ค์„ Routingํ•˜๋Š” ์„ค์ • ๋ฐฉ๋ฒ•๊ณผ filter๋ฅผ ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค. 0. API Gateway Spring Cloud Gateway๋Š” ๋ฐ›๋Š” ์š”์ฒญ์„ Predicate(์กฐ๊ฑด)์— ๋”ฐ๋ผ Filter๋ฅผ ๊ฑฐ์ณ, ๊ฐ Microservice์— Routing์„ ํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์—ฌ๊ธฐ์„œ Gateway์„œ๋ฒ„๋Š” Spring์˜ ๊ธฐ๋ณธ ๋‚ด์žฅ ์„œ๋ฒ„์ธ Tomcat์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  Netty๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ,Netty๋Š” ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ๋„คํŠธ์›Œํฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ์•„๋ฌด๋ž˜๋„ Gateway๊ฐ€ ๋ชจ๋“  ์š”์ฒญ๋“ค์„ ๋ฐ›๊ณ  Routingํ•˜๋Š” ์—ญํ• ์„ ํ•˜๋‹ค๋ณด๋‹ˆ, ๋น„๋™๊ธฐ ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ๋”..
ddonghyeo
'BackEnd/Spring Cloud' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก