마이크로서비스

개념

잘 정의된 API를 통해 통신하는 소규모의 독립적인 서비스로 구성

MSA

MSA

마이크로 서비스 아키텍처

  1. Hystrix (Circuit Breaker)
  2. Ribbon (Client Load Balancer)
  3. Eureka (Dynamic Service Discovery)
  4. Spring Cloud Feign
  5. Zuul (API Gateway)
  6. Configuration Server

구성

MSA MSA

컴포넌트

MSA

1. Hystrix (Circuit Breaker)

Circuit Breaker

Circuit Open/Close

CommandKey (설정)

hystrix: 
  command:
    default:
      execution.isolation.thread.timeoutInMilliseconds: 10000
      metrics.rollingStats.timeInMilliseconds: 10000
      circuitBreaker:
        requestVolumeThreshold: 1000
        errorThresholdPercentage: 50
        sleepWindowInMilliseconds: 5000
    'ClassName#MethodName(Object,String,Integer)':
      execution.isolation.thread.timeoutInMilliseconds: 10000
      metrics.rollingStats.timeInMilliseconds: 10000
      circuitBreaker:
        requestVolumeThreshold: 1000
        errorThresholdPercentage: 50
        sleepWindowInMilliseconds: 5000

Threadpool (설정)

hystrix: 
  threadpool: 
    default:
      allowMaximumSizeToDivergeFromCoreSize: true
      coreSize: 100
      maximumSize: 300
    'ClassName#MethodName(Object,String,Integer)':
      allowMaximumSizeToDivergeFromCoreSize: true
      coreSize: 100
      maximumSize: 300

Fallback

Timeout

2. Ribbon (Client Load Balancer)

ribbon

Client Load Balancer

ServerList

IRule

IPing

Retry

참고 (설정)

ServiceName:
  ribbon:
    eureka:
      enabled: false
    listOfServers: http://localhost:80
    ConnectTimeout: 5000
    ReadTimeout: 5000
    MaxAutoRetries: 1
    MaxAutoRetriesNextServer: 1

3. Eureka (Dynamic Service Discovery)

Dynamic Service Discovery

Eureka Server

Eureka Client

4. Spring Cloud Feign

Declarative Http Client

Feign + Hystrix, Ribbon, Eureka

참고 (설정)

feign:
  hystrix:
    enabled: true
  client:
    config:
      default:
        connectTimeout: 5000
        readTimeout: 5000
        loggerLevel: full
  httpclient.disableSslValidation: true
  httpclient.enabled: false
  okhttp.enabled: true

5. Zuul (API Gateway)

Zuul + Hystrix, Ribbon, Eureka

6. Configuration Server

config

참고 (설정)

spring:
  cloud:
    config:
      server:
        git:
          # uri: https://github.com/myapp/config # remote git
          uri: file:///home/user/myapp/config # local git

사례

넷플릭스

카카오

springcloud

SK 플래닛 11번가

springcloud

우아한 형제들

springcloud