Versions Compared

Key

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

...

  • [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에 ProductRemoteServiceImpl에 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 ]";
          }
      }

...