- ๋ชจ๋ ์ ๋ฌด ๋ก์ง์ด ํ๋์ ์ ํ๋ฆฌ์ผ์ด์ ํํ๋ก ํจํค์ง๋์ด ์๋น์ค
- ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๋ ๋ฐ์ดํฐ๊ฐ ํ ๊ณณ์ ๋ชจ์ฌ ์ฐธ์กฐ๋์ด ์๋น์ค๋๋ ํํ
- ๋น์ฆ๋์ค ๋ก์ง์ ์๋น์ค๋ค์ด ๋ถ๋ฆฌ๋์ด ์กด์ฌ
- ๋ ๋ฆฝ์ ์ผ๋ก ๋ฐฐํฌ ๊ฐ๋ฅ
- CI/CD๊ฐ ์ค์!!
- MSA ์ธํ๋ผ โ ๋ฏธ๋ค์จ์ด
- ํ๋ก์ ์ญํ , ์ธ์ฆ, ๊ถํ ๋ถ์ฌ, ์ํธํ, ์๋น์ค ๊ฒ์, ์์ฒญ ๋ผ์ฐํ , ๋ก๋ ๋ฐธ๋ฐ์ฑ
- ์๊ฐ ์น์ ๋ณต๊ตฌ ์๋น์ค
- ์๋น์ค๊ฐ์ ํต์ ๊ณผ ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ์๋ํ
- CNCF (Cloud Native Computing Foundation)
- Cloud Native Interactive Landscape
- ํ๊ฒฝ ์ค์ ์ ์ํด
Spring Cloud Config Serverํ์- ์ธ๋ถ ์ ์ฅ์์ ํ๋ฒ์ ํ๊ฒฝ์ค์ ๋ชจ์๋
- ์ ์ง๋ณด์๊ฐ ์ฌ์์ง๋ค.
- ์๋น์ค ๋ฑ๋ก๊ณผ ์์น ์ ๋ณด ํ์ธ์ ์ํด
Naming Server (Eureka) - Load Distribution (Load balancing) ์ ์ํด
Ribbon (Client Side),Spring Cloud Gateway์ฌ์ฉ- ์ธ๋ถ์ ํด๋ผ์ด์ธํธ๋ ์๋น์ค ์ ๋ณด๊ฐ ๊ฒ์ดํธ์จ์ด๋ฅผ ํต๊ณผํด์ Micro Service๋ก ์ด๋
- ๊ฐ๊ฐ์ Micro Service ๊ฐ์ ํต์ ์ ์ํด
FeignCliend์ด์ฉ - ์๊ฐํ๋ ๋ชจ๋ํฐ๋ง ์๋น์ค๋ฅผ ์ํด
Zipkin Distributed Tracing,Netflix API gateway์ด์ฉ- ๋ก๊ทธ ํ์ธ ๋ฑ
- ์ฅ์ ๋ฐ์ํ์ ๋ ํ๋ณต์ฑ ํจํด์ ์ํด
Hystrix์ด์ฉ
- ์ธ๋ถ์์ ๋ค๋ฅธ ์๋น์ค๋ค์ด ๋ค๋ฅธ micro service๋ฅผ ๊ฒ์ํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ฐ๋
- ์ผ์ข ์ ์ ํ๋ฒํธ๋ถ ์ฑ
- key์ value๊ฐ ์ ์ฅ๋์ด ์์
- ์ด๋ค ์๋น์ค๊ฐ ์ด๋ ์์น์ ์๋์ง ์ ์ ์์
- ๋ฑ๋ก, ๊ฒ์์ ๊ธฐ๋ฅ ์ ๊ณต
โ Spring Cloud Netflix Eureka ์ฌ์ฉํด์ ๊ตฌํ
- ํด๋ผ์ด์ธํธ๊ฐ ์์ ์ด ์ด์ฉํ๊ณ ์ถ์ ์๋น์ค์ ๋ํ ์์ฒญ ์ ๋ณด๋ฅผ Load Balancer, Gateway API์๊ฒ ์ ๋ฌ
- ๊ทธ ์์ฒญ ์ ๋ณด๊ฐ Service Discovery์ ์ ๋ฌ๋์ด ๋ด๊ฐ ํ์ํ ์ ๋ณด๊ฐ ์ด๋ ์๋ ๋ฌผ์ด๋ด
- ๊ทธ ์๋น์ค๋ ๋ช๋ฒ ์๋ฒ๋ก ๊ฐ์ธ์~ ๋ฅผ ๋ฐํํ๋ค.
- ๊ทธ๋ผ ๋ค์ Load Balancer๊ฐ ์๋ง๋ ์๋ฒ์ ์์ฒญ๊ฐ ์ ์ก, ๋ฐํ๊ฐ ๋ฐ๋๋ค.
server:
port: 8761
spring:
application:
name: discoveryservice
eureka:
client:
register-with-eureka: false
fetch-registry: false- register-with-eureka: ์์ ์ ์ ๋ณด๋ฅผ ์์ ์๊ฒ ๋ฑ๋กํ๋ ์์ .. ์๋ฏธ ์๊ธฐ ๋๋ฌธ์ false๋ก.. ๊ทธ๋ฅ ์๋ฒ๋ก๋ง ๊ธฐ๋๋๋ฉด ๋จ
- fetch-registry: ์ด ํด๋ผ์ด์ธํธ๊ฐ ๋ค๋ฅธ ์๋น์ค์ endpoints์ ๋ํ ์ ๋ณด๋ฅผ ๋ค์ด๋ก๋ํ๊ธฐ ์ํด ์ ๋ ์นด ์๋ฒ์ ์ฐ๊ฒฐ์ ์๋ํ ์ง ์ฌ๋ถ
- ์ ๋ ์นด์ ๋ฑ๋ก๋๋ ์๋น์ค๋ค์ ์ ๋ณด๋ฅผ ๊ฐฑ์ ํ๊ธฐ ์ํ ์ฉ๋!
https://github.com/spring-cloud/spring-cloud-release/wiki/Supported-Versions
Spring boot์ Eureka ๋ฒ์ ๋ง์ถ๊ธฐ!
- ecommerce ํ๋ก์ ํธ - EcommerceApplication.java
@SpringBootApplication
@EnableEurekaServer
public class EcommerceApplication {
public static void main(String[] args) {
SpringApplication.run(EcommerceApplication.class, args);
}
}- user-service ํ๋ก์ ํธ - UserServiceApplcation.java
@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class, args);
}
}- user-service ํ๋ก์ ํธ
server:
port: 9001
spring:
application:
name: user-service
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eureka- -D : ์ต์ ์ถ๊ฐํ๊ฒ ๋ค
-D : ์ต์ ์ถ๊ฐํ๊ฒ ๋ค
๋๋, ํฐ๋ฏธ๋์์
./gradlew bootRun --args='--server.port=9003'maven์ด ์๋๋ผ gradle๋ก ์งํ์ค์ด์ ๋ถ๋ค - ์ธํ๋ฐ | ์ง๋ฌธ & ๋ต๋ณ
user-service 3๊ฐ๊ฐ ์คํ ์ค!!!
./gradlew clean build
./gradlew build
./gradlew bootRun --args='--server.port=9004'๊ทผ๋ฐ ์ด๋ ๊ฒ ๊ณ์ ํฌํธ ๋ฐ๊ฟ์ฃผ๋ ๊ฑฐ ๊ท์ฐฎ์..
server:
port: 0
spring:
application:
name: user-service
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eurekaport: 0๋ฒ โ ๋๋ค์ผ๋ก
์ด๋ ๊ฒ ํ๋ฉด ๋ช๊ฐ๋ฅผ ์คํํด์ ์ฃ๋ค ๋๋คํฌํธ๊ฐ ๋ถ์ฌ๋ผ์ ์คํ๋๋๋ผ๋ 0๋ฒ ํฌํธ๋ฐ์ ์๋ธ (์ ๋ ์นด์)
server:
port: 0
spring:
application:
name: user-service
eureka:
instance:
instance-id: ${spring.cloud.client.hostname}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eureka์ ๋ ๊ฒ yml ์์ ํด์ฃผ๋ฉด ์ธ์คํด์ค ์์ด๋ ์ถ๊ฐ๋ผ์ ๋ถ๋ฆฌ๋ผ์ ๋์ด!!
scaling ์์ ํด์ฃผ๊ธฐ ์ํด ์ฌ๋ฌ ์ธ์คํด์ค ๋ง๋ค๊ณ ๊ฐ๊ฐ์ ์ธ์คํด์ค ์๋น์ค๋ ์ ๋ ์นด์ ์ ๋ฑ๋ก๋จ!
๋ก๋ ๋ฐธ๋ฐ์ค!!!
์ฌ์ฉ์๊ฐ ์ค์ ํ ๋ผ์ฐํ ์ค์ ์ ๋ฐ๋ผ ๊ฐ๊ฐ ์๋ํฌ์ธํธ๋ก ํด๋ผ์ด์ธํธ๋ฅผ ๋์ ํด ์์ฒญํ๊ณ ์๋ต์ ๋ฐ์ผ๋ฉด ๋ค์ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํด์ฃผ๋ ํ๋ก์ ์ญํ ์ ํจ
์์คํ ๋ด๋ถ ๊ตฌ์กฐ๋ ์จ๊ธฐ๊ณ ์ธ๋ถ์ ์์ฒญ์ ๋ํด ์ ์ ํ ๊ฐ๊ณตํด ์๋ตํ ์ ์๋ ์ฅ์ ์ด ์๋ค.
MS๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ๋น๋๊ฐ ๋๊ณ ๋ฐฐํฌ๊ฐ ๋ ์ ์๋ ์ฅ์ .
ํ์ง๋ง Client side์์๋โฆ
ํด๋ผ์ด์ธํธ ์ฌ์ด๋์์ ๋ง์ดํฌ๋ก์๋น์ค์ ์ฃผ์๋ฅผ ์ง์ ์ด์ฉํด์, ์ด๊ฑธ ์๋ํฌ์ธํธ. ์๋ํฌ์ธํธ๋ฅผ ์ง์ ํธ์ถ ํ์ ๊ฒฝ์ฐ client side์ ์๋ ์ดํ๋ฆฌ์ผ์ด์ ๋ ๊ฐ์ด ์์ ๋ฐฐํฌ๊ฐ ๋์ด์ผํจ
์ด๋ฌ๋ค ๋ณด๋ ๋จ์ผ ์ง์ ์ ์ ๊ฐ์ง๊ณ ์๋ ํํ๋ก์จ ๊ฐ๋ฐํ๋ ๊ฒ ํ์.
์๋ฒ๋จ(๋ฐฑ์๋)์ ์ค๊ฐ์ ๊ฒ์ดํธ์จ์ด ์ญํ ์ ํด์ค์์๋ ์ผ์ข ์ ์ง์ ๋ก, ๊ฒ์ดํธ์จ์ด๋ฅผ ๋๊ณ ๊ฐ๊ฐ์ ms์ ์์ฒญ๋๋ ๋ชจ๋ ์ ๋ณด์ ๋ํด ์๊ฐ ์ผ๊ด์ ์ผ๋ก ์ฒ๋ฆฌ
๋ชจ๋ฐ์ผ์ฑ๋ ์๊ด์์.
์ง์ ์ ์ผ๋ก ms๋ฅผ ํธ์ถํ์ง ์๊ณ ํด๋ผ์ด์ธํธ๋ ๊ฒ์ดํธ์จ์ด๋ง ์๋ํจ.
๋ฐ๋ผ์ ๊ฒ์ดํธ์จ์ด์์ ํ์๋ก ํ๋ ์ ๋ณด๋ฅผ ๋ณ๊ฒฝํ๊ณ ๊ฐฑ์ ํ๋ ์์ ์ด ์์ํ๋น.
- ์ธ์ฆ ๋ฐ ๊ถํ ๋ถ์ฌ
- ๋ง์ดํฌ๋ก์๋น์ค ๊ฒ์ ํตํฉ
- ์๋ต ์บ์ฑ
- ์ ์ฑ , ํ๋ก ์ฐจ๋จ๊ธฐ ๋ฐ QoS ๋ค์ ์๋
- ์๋ ์ ํ
- ๋ถํ ๋ถ์ฐ
- ms๊ฐ ๊ฐ์ง๊ณ ์๋ ํ๋์ ์๋น์ค์ ๋ด์ฉ์ ์ธ๊ฐ์ ์ธ์คํด์ค๊ฐ ๋๋ ์ ์์ ํ๋ค๊ณ ๊ฐ์
- ms1, ms2, ms3
- ๊ทธ๋ผ ์ด๋๋ก ์์ฒญ ๋ณด๋ผ์ง ํ๋จ
- ๋ก๊น (๊ฐ๊ฐ์ ms๊ฐ ํ๋์ solution์ ์ด์ฉํด ๋ก๊ทธ๋ฅผ ๋ชจ์๋์์๋์์. ๋ฌผ๋ก ๋ก๊ทธ๋ง ์ ๋ฌธ์ ์ผ๋ก ์ฒ๋ฆฌํด์ค์ ์๋ ์์คํ (ex. ELK)์จ์ ์ฒ๋ฆฌํ ์๋ ์๋ค.)
- ์ถ์ (์ด๋ค ms๊ฐ ๋๊ตฌ์ ์ํด ํธ์ถ, ์ง์ ์ ์ด ๋๊ตฌ, ์ด๋๋ก ์ด๋ ๋ฑ๋ฑ - ์ถ์ ๊ด๊ณ ์ค์ํจ!!)
- ์๊ด ๊ด๊ณ
- ํค๋, ์ฟผ๋ฆฌ ๋ฌธ์์ด ๋ฐ ์ฒญ๊ตฌ ๋ณํ
- IP ํ์ฉ ๋ชฉ๋ก์ ์ถ๊ฐ
- ๋ฐฉํ๋ฒฝ, ํ๋ก์ ์ญํ ํด์ฃผ๋ ๊ฒ์ดํธ์จ์ด!
-
Spring Cloud์์์ MSA๊ฐ ํต์
-
RestTemplate
- ํ๋์ ์น ์ดํ๋ฆฌ์ผ์ด์ ์์ ๋ค๋ฅธ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉํ๊ธฐ ์ํด ์์ฃผ ์ฌ์ฉ๋์๋ API
-
Feign Client
- ์ถ๊ฐ์ ์ผ๋ก ํธ์ถํ๊ณ ์ถ์ ์๋น์ค
@FeignClient๋ก ๋ฑ๋ก- ์ง์ ์ ์ธ ์๋ฒ ์ฃผ์, ํฌํธ ๋ฒํธ ์์ด ms์ด๋ฆ ๊ฐ์ง๊ณ ํธ์ถ ๊ฐ๋ฅ
- user๋ผ๋ ์๋น์ค ์์ stores๋ผ๋ ์๋น์ค๊ฐ ์์ ์ด ๊ฐ์ง๊ณ ์๋ API ์ฒ๋ผ ์์ ๋กญ๊ฒ ํธ์ถํด์ ์ฌ์ฉ ๊ฐ๋ฅ
- ์ถ๊ฐ์ ์ผ๋ก ํธ์ถํ๊ณ ์ถ์ ์๋น์ค
-
-
Ribbon: Client side Load Balancer
- ์ด์ฐฝ๊ธฐ์๋ ๋ก๋ ๋ฐธ๋ฐ์ค๋ฅผ ํด์ฃผ๊ธฐ ์ํด ๋ฆฌ๋ณธ์ด๋ผ๋ ์๋น์ค ์ ๊ณตํจ
- ๋ฌธ์ : ๋ฆฌ๋ณธ์ด๋ผ๋ ์๋น์ค ์์ฒด๋ ์ต๊ทผ์ Functional API(react java) - ๋น๋๊ธฐ ์ฒ๋ฆฌ๊ฐ ์ ์๋๊ธฐ ๋๋ฌธ์ ์ต๊ทผ์ ์ ์ฌ์ฉx
- ์๋น์ค ์ด๋ฆ์ผ๋ก ํธ์ถ
- ํด๋ผ์ด์ธํธ ์์์ ํ์ํ ๋ฐ์ดํฐ ํธ์ถ
- Health Check
- ํด๋น ์๋น์ค ์ ์๋ ์ค์ธ์ง ํ์ธ
- service 3๊ฐ ์๋ค๊ณ ๊ฐ์
- ํด๋ผ์ด์ธํธ ๋ด๋ถ์ ribbon์ ๋๊ณ (์ด๋๋ api gateway ์ฌ์ฉx) ์ด๊ฑธ๋ก ์ด๋ํ๊ณ ์ํ๋ ms์๋น์ค์ ์ฃผ์๊ฐ ๊ด๋ฆฌ
- Client Side์์!!!!!
- ์ฅ์ : ์ธ๋ถ์ ์๋ ๋ง์ดํฌ๋ก ์๋น์ค๋ฅผ ํธ์ถํ๊ธฐ ์ํด ip์ ํฌํธ๋ฒํธ๋ฅผ ๋ช ์ํ๋ ๊ฒ ์๋๋ผ, ms์ ์ด๋ฆ๋ง ๊ฐ์ง๊ณ ํธ์ถํ ์ ์์
- ์ต๊ทผ์๋ ์ฌ์ฉX
- ๊ตฌ์ฑ
- ํ
์คํธ
- First Service
- Second Service
- Spring Boot: 2.3.8
- Netflix Zuul โ Gateway
- ์ญํ
- Routing
- API gateway
- ์ญํ
- ํ
์คํธ
- ์๋ ๋ ์ด์ ์ฌ์ฉ X
server:
port: 8000
spring:
application:
name: my-zuul-service
zuul:
routes:
first-service:
path: /first-service/**
url: http://localhost:8081
second-service:
path: /second-service/**
url: http://localhost:8082zuul์ด๋ผ๋ ์๋น์ค๊ฐ 8000์ผ๋ก first-service/**๋ผ๋ ์์ฒญ์ด ๋ค์ด์ค๋ฉด
8081๋ก ํฌ์๋ฉ ์ํจ๋ค.
http://localhost:8000/first-service/welcome
server:
port: 8000
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: first-service
uri: http://localhost:8081/
predicates:
- Path=/first-service/**
- id: second-service
uri: http://localhost:8082/
predicates:
- Path=/second-service/**- Zuul๊ณผ๋ ๋ค๋ฅด๊ฒ Controller์ ๋งตํ์ ํด์ค์ผ ํ๋ค.
http://localhost:8081/first-service/**์ด๋ ๊ฒ ๊ฐ๊ธฐ ๋๋ฌธ์ด๋ค.
- Zuul ๋์ Spring Cloud Gateway ์จ๋ณด์.
predicates: ์กฐ๊ฑด- first-service๋ผ๋ ์์ฒญ ๋ค์ด์ค๋ฉด 8081๋ก ๊ฐ๊ฒ ๋ค.
- Spring Cloud Gateway: ๋น๋๊ธฐ ์ฒ๋ฆฌ ์ ๊ณต
- .yml ๋ถ๋ถ๋์ FilterConfig.java ์ฌ์ฉํด๋ณด๊ธฐ
server:
port: 8000
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: gateway-service
# cloud:
# gateway:
# routes:
# - id: first-service
# uri: http://localhost:8081/
# predicates:
# - Path=/first-service/**
# - id: second-service
# uri: http://localhost:8082/
# predicates:
# - Path=/second-service/**- FilterConfig.java
public RouteLocator gateWayRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/first-service/**") //์ด ์์ฒญ ๋ค์ด์ค๋ฉด
.filters(f-> f.addRequestHeader("first-request", "first-request-header")
.addResponseHeader("first-response", "first-response-header"))
.uri("http://localhost:8081/")) //์ฌ๊ธฐ๋ก ์ด๋ํ๊ฒ ๋ค
.route(r -> r.path("/second-service/**")
.filters(f-> f.addRequestHeader("second-request", "second-request-header")
.addResponseHeader("second-response", "second-response-header"))
.uri("http://localhost:8082/"))
.build();
}- ํํฐ๋ฅผ yml์์ ๋ฃ๊ธฐ
server:
port: 8000
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: first-service
uri: http://localhost:8081/
predicates:
- Path=/first-service/**
filters:
- AddRequestHeader=first-request, first-request-header2
- AddResponseHeader=first-response, first-response-header2
- id: second-service
uri: http://localhost:8082/
predicates:
- Path=/second-service/**
filters:
- AddRequestHeader=second-request, second-request-header2
- AddResponseHeader=second-response, second-response-header2- FilterConfig.java ํ์ผ์ ์ด๋ ธํ ์ด์ ๋ค ์ฃผ์ ๊ฑธ์ด์ค ์์ธ๋ ค๊ณ
- .yml์ ์ถ๊ฐํ key-value response ์ ํ์ธ๋๋น!!
@Component
@Slf4j
public class CustomFilter extends AbstractGatewayFilterFactory<CustomFilter.Config> { //์ฐ๋ฆฌ๊ฐ ์ง๊ธ ๋ง๋ค๊ณ ์๋ CustomFilter์ Config
public CustomFilter() {
super(Config.class);
}
@Override
public GatewayFilter apply(Config config) { //์ฐ๋ฆฌ๊ฐ ์ ์ฉํ๊ณ ์ถ์ ๋ด์ฉ
// Custom Pre Filter
return (exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest(); //exchage๋ก๋ถํฐ request ๋ฐ์์ค๊ธฐ
ServerHttpResponse response = exchange.getResponse(); //response ๋ฐ์์ค๊ธฐ
log.info("Custom PRE filter: request id -> {}", request.getId());
// Custom Post Filter - ์ฒ๋ฆฌ ํ
return chain.filter(exchange).then(Mono.fromRunnable(() -> { //chain์ ์ฐ๊ฒฐ -> ํํฐ ์ถ๊ฐ
// Mono : ๋ฐ์ดํฐ ํ์
ํ๋ ์ค ๊ฑฐ์
// ๋น๋๊ธฐ ๋ฐฉ์์์ ๋จ์ผ๊ฐ์ผ ๋ ์ฌ์ฉ, response ํ ๋ response status code๋ฅผ ์ถ๋ ฅ
log.info("Custom POST filter: response code -> {}", response.getStatusCode());
}));
};
}
public static class Config {
// Put the configuration properties
}
}- CustomFilter ๋ฑ๋ก
- ํ์ฌ first-service, second-service์ ๋์ผํ
CustomFilter์ ์ฉ ์ค. - ์ด๋ ๊ฒ ๋ผ์ฐํ ์ ๋ณด๋ง๋ค ๋ฑ๋กํ์ง๋ง๊ณ
- ๊ณตํต์ ์ธ ํํฐ ์์ผ๋ฉด ํ๋ฒ์ ๋ฑ๋กํ์
- ์ ์ฒด ๋ผ์ฐํฐ์ ์ ์ฉ!
- ๊ฐ์ฅ ๋จผ์ ์คํ๋๊ณ ๊ฐ์ฅ ๋์ค์ ์ข ๋ฃ๋จ.
.
.
.
spring:
application:
name: gateway-service
cloud:
gateway:
default-filters:
- name: GlobalFilter
args:
baseMessage: Spring Cloud Gateway GlobalFilter
preLogger: true
postLogger: true
routes:
- id: first-service
uri: http://localhost:8081/
predicates:
- Path=/first-service/**
filters:
# - AddRequestHeader=first-request, first-request-header2
# - AddResponseHeader=first-response, first-response-header2
- CustomFilter
.
.
.- ๊ทผ๋ฐ ์ ๋ ๊ฒ yml์ ๊ฐ์ ์ง์ ํ์ดํ ํ๋ฉด ๊ท์ฐฎ๋ค.
- ์ถํ์โฆ
- ์ผ์ข ์ ์ปค์คํ ํํฐ
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServiceApplication.class, args);
}
}@EnableEurekaServer์ถ๊ฐ!! - ์๋ฒ๋ก ๋ฑ๋ก
@SpringBootApplication
@EnableEurekaClient
public class GatewayServiceApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServiceApplication.class, args);
}
}@EnableEurekaClient์ถ๊ฐ!! - ํด๋ผ์ด์ธํธ๋ก ๋ฑ๋ก
server:
port: 8000
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eurekaregister-with-eureka: trueโ ์ ๋ ์นด์ ๋ฑ๋ก
- ์์ ๊ฒ์ดํธ์จ์ด๋ ๋๊ฐ์ด ์ ๋ ์นด ํด๋ผ์ด์ธํธ๋ก ๋ฑ๋กํด์ค
์ฌ๊ธฐ ์คโฆ
์ด ์ด๋ฆ!!!!
์ด์ uri ์ ์ฐ๊ณ ์ Application ์ด๋ฆ์ผ๋ก ๋ก๋๋ฐธ๋ฐ์ฑํ ๊ฒ์
routes:
- id: first-service
uri: lb://MY-FIRST-SERVICE
predicates:
- Path=/first-service/**
filters:
- CustomFilter
- id: second-service
uri: lb://MY-SECOND-SERVICE
predicates:
- Path=/second-service/**- uri ๋ฐ๊ฟ์ฃผ๊ธฐ
uri: lb://MY-FIRST-SERVICEuri: lb://MY-SECOND-SERVICE
๋ง์ฝ ์ด ์ํ๋ผ๋ฉดโฆ
๊ฒ์ดํธ์จ์ด์์ uri: lb://MY-FIRST-SERVICE ์ด ์์ฒญ์ ๋ฐ์์ ๋ 8081 ๋๋ 9091 ์ด ์ค ์๋ฌด ๊ณณ์ด๋ ๊ฐ ๊ฒ์ด๋ค.
server:
port: 0
spring:
application:
name: my-first-service
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}- ํฌํธ๋ฒํธ: 0
- ๋๋ค ํฌํธ๋ฒํธ ๋ถ์ฌ ์ํด
- ์ธ์คํด์ค ์ถ๊ฐ
@GetMapping("/check")
public String check(HttpServletRequest request) {
log.info("Server port={}", request.getServerPort());
return String.format("Hi, there. This is a mesasge from First Service on PORT %s", env.getProperty("local.server.port"));
}request.getServerPort()env.getProperty("local.server.port")
- round-robin ๋ฐฉ์์ผ๋ก ๋ฒ๊ฐ์๊ฐ๋ฉด์ ํธ์ถํด์ค๋น.
































