...
02. Hystrix Fallback 적용하기
가. Fallback 적용하기
Info |
---|
git checkout tags/step-2-hystrix-fallback -b step-2-hystrix-fallback |
...
- Product → Display 호출 확인
Info icon false - Product 확인
- Display 확인
나. Fallback 원인 출력하기
Info |
---|
git checkout tags/step-2-hystrix-fallback2 -b step-2-hystrix-fallback2 |
- [display] ProductRemoteServiceImp에 Fallback Method 에 Throwable추가
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, Throwable t) { System.out.println("t = " + t); return "[ this product is sold out ]"; } }
- Display 호출 확인
- http://localhost:8081/displays/11111
Code Block 2020-02-25 11:32:22.068 INFO 69092 --- [io-8081-exec-10] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2020-02-25 11:32:22.068 INFO 69092 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2020-02-25 11:32:22.174 INFO 69092 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 106 ms t = org.springframework.web.client.HttpServerErrorException: 500 null
- http://localhost:8081/displays/11111
03. Hystrix로 Timeout 처리하기
...