Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse

Table of Contents

01. Hystrix 사용하기

Info

Display → Product 연동 구간에 Circuit Breaker를 적용!

...

Code Block
@HystrixCommand


02. Hystrix Fallback 적용하기

Info

git checkout tags/step-2-hystrix-fallback -b step-2-hystrix-fallback

  • 개요
    • Display 서비스는 외부 Server인 Product API와 연동되어있음
    • Product API에 장애가 나더라도 Display의 다른 서비스는 이상없이 동작하였으면 합니다
    • Product API에 응답 오류인경우, Default값을 넣어 주고 싶습니다


  • [product] ProductController에서 항상 Exception 던지게 수정하기 (장애 상황 흉내)
    • Code Block
      @RestController
      @RequestMapping("/products")
      public class ProductController {
      
          @GetMapping(path = "{productId}")
          public String getProductInfo(@PathVariable String productId) {
              // return "[product id = " + productId + " at " + System.currentTimeMillis() + "]";
              throw new RuntimeException("I/O Exception");
          }
      }
  • [display] ProductRemoteServiceImp에 Fallback Method 작성하기
    • Code Block
      @Service
      public class ProductRemoteServiceImpl implements ProductRemoteService {
      
          private static final String url = "http://localhost:8082/products/";
          private final RestTemplate restTemplate;
      
          public ProductRemoteServiceImpl(RestTemplate restTemplate) {
              this.restTemplate = restTemplate;
          }
      
          @Override
          @HystrixCommand(fallbackMethod = "getProductInfoFallback")
          public String getProductInfo(String productId) {
              return this.restTemplate.getForObject(url + productId, String.class);
          }
      
          public String getProductInfoFallback(String productId) {
              return "[ this product is sold out ]";
          }
      }
  • Product → Display 호출 확인
Info

Image Added

Image Added




Info

git checkout tags/step-2-hystrix-fallback2 -b step-2-hystrix-fallback2


03. Hystrix로 Timeout 처리하기




04. Hystrix Circuit Open 테스트