I need to timeout my Rest Api when no response is returned. For example, when I make a request and if it takes more than 5 seconds to return a response, then Timeout.
In order to implement this, I opted for Circuit Breaker using Hystrix. But I am not sure whether it is the right way to approach this problem and if it's all good, should Hystrix be configured more?
My current implementation looks like,
Main class
@SpringBootApplication
@EnableCircuitBreaker
class MyApplication{
}
RestController
@GetMapping("/data")
@HystrixCommand(commandKey="response")
public String getResponse(){
Thread.sleep(10000);
.....
}
application.properties
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
When timed out, it throws a HystrixRunTimeException and that's handled with a Custom Exception handler.
Is this the right approach to implement Request Timeout?