...
03. Hystrix로 Timeout 처리하기
Infocode |
---|
git checkout tags/step-2-hystrix-tiemout timeout -b b step-2-hystrix-tiemout timeout |
- [product] ProductController의 throw Exception을 Thread.sleep(2000)로 수정
Code Block @RestController @RequestMapping("/products") public class ProductController { @GetMapping(path = "{productId}") public String getProductInfo(@PathVariable String productId) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return "[product id = " + productId + " at " + System.currentTimeMillis() + "]"; //throw new RuntimeException("I/O Exception"); } }
- [display] application.yml 수정하여 Hystrix Timeout 시간 조정하기
Code Block hystrix: command: default: # command key. use 'default' for global setting. execution: isolation: thread: timeoutInMilliseconds: 1000
- Display → Product 호출 하기
Info icon false Code Block 2020-02-25 12:12:54.768 INFO 92144 --- [io-8081-exec-10] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2020-02-25 12:12:54.769 INFO 92144 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2020-02-25 12:12:54.857 INFO 92144 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 88 ms t = com.netflix.hystrix.exception.HystrixTimeoutException
...