[Spring Boot & MSA] Zuul API Gateway

μ›μ•Œλ ‰μŠ€Β·2020λ…„ 8μ›” 12일
0

Spring Boot MSA

λͺ©λ‘ 보기
11/12
post-thumbnail

βœ” κΉƒν—ˆλΈŒ μ†ŒμŠ€μ½”λ“œ
βœ” Udemy κ°•μ˜

πŸš€ ν”„λ‘œμ νŠΈ ꡬ성

βœ” μ˜μ‘΄μ„± μ„€μ •

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

βœ” @EnableZuulProxy μ–΄λ…Έν…Œμ΄μ…˜ μΆ”κ°€

@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class ZuulServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(ZuulServiceApplication.class, args);
	}
}

βœ” λΆ€νŠΈμŠ€νŠΈλž˜ν•‘(bootstrap.yml)

spring:
  application:
    name: zuul-service

  profiles:
    active: default

  cloud:
    config:
      uri: http://localhost:8888

βœ” ν”„λ‘œνΌν‹° μ„€μ •(원격 μ €μž₯μ†Œ λ‚΄μ˜ zuul-service.yml)

server:
  port: 5555

eureka:
  instance:
    preferIpAddress: true

  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8010/eureka/

βœ” νžˆμŠ€νŠΈλ¦­μŠ€μ™€ 리본 νƒ€μž„μ•„μ›ƒ μ„€μ •

Β Β Β Β  μ£ΌμšΈμ€ λ„·ν”Œλ¦­μŠ€μ˜ νžˆμŠ€νŠΈλ¦­μŠ€μ™€ 리본 라이브러리λ₯Ό μ‚¬μš©ν•΄ 였래 μˆ˜ν–‰λ˜λŠ” μ„œλΉ„μŠ€ 호좜이 μ„œλΉ„μŠ€ κ²Œμ΄νŠΈμ›¨μ΄μ˜ μ„±λŠ₯에 영ν–₯을 λ―ΈμΉ˜μ§€ μ•Šλ„λ‘ ν•©λ‹ˆλ‹€. 기본적을 μ£ΌμšΈμ€ μš”μ²­μ„ μ²˜λ¦¬ν•˜λŠ” 데 1초 이상 κ±Έλ¦¬λŠ” λͺ¨λ“  ν˜ΈμΆœμ„ μ’…λ£Œν•˜κ³  HTTP 500 μ—λŸ¬λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€(이것은 히슀트릭슀 κΈ°λ³Έ λ™μž‘μž…λ‹ˆλ‹€).

주울둜 μ‹€ν–‰ 쀑인 λͺ¨λ“  μ„œλΉ„μŠ€μ— λŒ€ν•΄ 히슀트릭슀 νƒ€μž„μ•„μ›ƒμ„ μ„€μ •ν•˜λ €λ©΄ hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds ν”„λ‘œνΌν‹°λ₯Ό μ‚¬μš©ν•˜λ©΄ λ©λ‹ˆλ‹€. νŠΉμ • μ„œλΉ„μŠ€μ—μ„œλ§Œ λ³„λ„μ˜ 히슀트릭슀 νƒ€μž„μ•„μ›ƒμ„ μ„€μ •ν•˜λ €λ©΄ default 뢀뢄을 ν•΄λ‹Ή μ„œλΉ„μŠ€μ˜ ID둜 λ°”κΎΈλ©΄ λ©λ‹ˆλ‹€.

λ„·ν”Œλ¦­μŠ€μ˜ 리본은 5초 이상 μˆ˜ν–‰λ˜λŠ” ν˜ΈμΆœμ„ νƒ€μž„μ•„μ›ƒν•©λ‹ˆλ‹€. 5초 이상 μˆ˜ν–‰λ˜λŠ” ν˜ΈμΆœμ— λŒ€ν•΄μ„ΈλŠ” μ½”λ“œ μž¬κ²€ν† κ°€ κ°•λ ₯히 ꢌμž₯λ˜μ§€λ§Œ ribbon.ReadTimeout ν˜Ήμ€ {service.name}.ribbon.ReadTimeout ν”„λ‘œνΌν‹°λ₯Ό μ‚¬μš©ν•΄ 리본의 νƒ€μž„μ•„μ›ƒμ„ μž¬μ •μ˜ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Note: 5초 μ΄μƒμ˜ νƒ€μž„μ•„μ›ƒ ꡬ성은 νžˆμŠ€νŠΈλ¦­μŠ€μ™€ 리본 λͺ¨λ‘μ— λŒ€ν•΄μ„œ 섀정을 ν•΄μ€˜μ•Ό ν•©λ‹ˆλ‹€.

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 7000

ribbon:
  ReadTimeout: 7000
profile
Alex's Develog πŸ€”

0개의 λŒ“κΈ€