Software Architecture/MSA

[MSA ๊ตฌ์ถ•ํ•˜๊ธฐ] 5. Spring Cloud Gateway ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ (API Gateway)

bu119 2024. 3. 15. 21:00
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ”Š ์šฐ๋ฆฌ๋Š” Spring Cloud๋ฅผ ํ™œ์šฉํ•˜์—ฌ MSA๋ฅผ ๊ตฌ์ถ•ํ•œ๋‹ค.

๐Ÿ”Š ์ด๋ฒˆ์—๋Š”, Spring Cloud Gateway๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ API Gateway๋ฅผ ๊ตฌ์ถ•ํ•  ๊ฒƒ์ด๋‹ค. 

 

API Gateway ํŒŒํŠธ 1

 

API Gateway๋ž€?

์‚ฌ์šฉ์ž๊ฐ€ ์„ค์ •ํ•œ Routing ์„ค์ •์— ๋”ฐ๋ผ ๊ฐ endpoint๋กœ client๋ฅผ ๋Œ€์‹ ํ•ด์„œ ์š”์ฒญํ•˜๊ณ , ์‘๋‹ต์„ ๋ฐ›์œผ๋ฉด ๋‹ค์‹œ client์—๊ฒŒ ์ „๋‹ฌํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

Spring Cloud์—์„œ๋Š” Spring Cloud Gateway๊ฐ€ API Gateway์˜ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. 

 

Spring Cloud Gateway๋ž€?

์Šคํ”„๋ง ํด๋ผ์šฐ๋“œ ๊ฒŒ์ดํŠธ์›จ์ด๋Š” MSA ๊ฐ€์žฅ ์•ž๋‹จ์—์„œ ํด๋ผ์ด์–ธํŠธ๋“ค๋กœ ๋ถ€ํ„ฐ ์˜ค๋Š” ์š”์ฒญ์„ ๋ฐ›์€ ํ›„ ๊ฒฝ๋กœ์™€ ์กฐ๊ฑด์— ์•Œ๋งž์€ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ๋กœ์ง์— ์š”์ฒญ์„ ์ „๋‹ฌํ•˜๋Š” ๊ฒŒ์ดํŠธ์›จ์ด์ด๋‹ค. ๊ฒŒ์ดํŠธ์›จ์ด๋Š” ๊ฐœ๋…์ ์œผ๋กœ๋Š” ์•„์ฃผ ๋‹จ์ˆœํ•˜์ง€๋งŒ ๊ฐ€์žฅ ์•ž๋‹จ์—์„œ ๋ฌด์ค‘์ง€ ์ƒํƒœ๋กœ ๋ชจ๋“  ์š”์ฒญ์„ ๋ฐ›์•„์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์„ค์ •ํ•˜๊ธฐ์— ๊นŒ๋‹ค๋กญ๋‹ค.

 

Spring Cloud Gateway์˜ ํŠน์„ฑ

๊ธฐ์กด์— ์ œ์ž‘ํ–ˆ๋˜ ์Šคํ”„๋ง ๋ถ€ํŠธ, Eureka, Config์™€ ๊ฐ™์€ ์„œ๋น„์Šค๋“ค์„ ๋ธ”๋กœํ‚น ๊ธฐ๋ฐ˜์œผ๋กœ ๋ชจ๋‘ ํ†ฐ์บฃ ์—”์ง„์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๊ฒŒ์ดํŠธ ์›จ์ด์˜ ๊ฒฝ์šฐ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์ฒ˜๋ฆฌ ๋ณด๋‹จ ๋‹จ์ˆœํ•˜๊ฒŒ ์ง€๋‚˜๊ฐ€๋Š” ํ†ต๋กœ ์ฆ‰, I/O ์ฒ˜๋ฆฌ๋ฅผ ์ค‘์ ์ ์œผ๋กœ ์ง„ํ–‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋…ผ ๋ธ”๋กœํ‚น ๋ฐฉ์‹์œผ๋กœ ๋™์ž‘ํ•˜๋Š” WebFlux์™€ ๋„คํ‹ฐ์—”์ง„์„ ์‚ฌ์šฉํ•œ๋‹ค.

WebFlux๋Š” ๊ธฐ์กด์— ์Šคํ”„๋ง ๋ถ€ํŠธ์—์„œ ์‚ฌ์šฉํ–ˆ๋˜ JPA์™€ ๊ฐ™์€ ๋ธ”๋กœํ‚น ๋ฐฉ์‹์˜ ์˜์กด์„ฑ๋“ค์„ ๋ชจ๋‘ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌํ˜„์— ์•ž์„œ ๋งŽ์€ ํ•™์Šต์ด ํ•„์š”ํ•˜๋‹ค.

 

๐Ÿ”Š Spring Cloud์—์„œ ์ œ๊ณตํ•˜๋Š” Spring Cloud Gateway๋ฅผ ํ™œ์šฉํ•˜์—ฌ API Gateway๋ฅผ ๊ตฌ์ถ•ํ•  ๊ฒƒ์ด๋‹ค.

 


Spring Cloud Gateway ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

 

Spring Cloud Gateway ์„ค์ •์„ ์œ„ํ•œ ์˜์กด์„ฑ ์ถ”๊ฐ€

ํ•„์ˆ˜ ์˜์กด์„ฑ

  • Reactive Gateway
// build.gradle

ext {
	set('springCloudVersion', "2023.0.0")
}

dependencies {
	implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'io.projectreactor:reactor-test'
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

 

Spring Initializr์—์„œ ์˜์กด์„ฑ์œผ๋กœ Reactive Gateway๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•œ๋‹ค. Gateway๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์•ˆ๋œ๋‹ค!!!!

 

๐Ÿ”Š ๊ทธ ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์•„๋ž˜ ํฌ์ŠคํŒ…์„ ์ฝ์–ด๋ณด์ž.

https://bu119.tistory.com/92

 

[MSA] Spring Cloud Gateway์™€ Netflix Zuul์˜ ์ฐจ์ด์  (API Gateway)

๐Ÿ”Š Spring Cloud Gateway๋ฅผ ํ™œ์šฉํ•˜์—ฌ API Gateway๋ฅผ ๊ตฌ์ถ•ํ•  ๋•Œ Spring Initializr์—์„œ ์˜์กด์„ฑ์œผ๋กœ Gateway๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์•ˆ ๋˜๊ณ  Reactive Gateway๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ? โ“ API Gateway ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ

bu119.tistory.com


์ฐธ๊ณ  ์ž๋ฃŒ

https://velog.io/@korea3611/Spring-Boot-Spring-Cloud-Gateway-%EB%A7%8C%EB%93%A4%EA%B8%B0-MSA2

https://substantial-park-a17.notion.site/8-84d3a62b9a214035a42ab49aae704a34

728x90
๋ฐ˜์‘ํ˜•