I am building a Spring batch job and in the Item processor step I am consuming an external end-point and saving the values to DB. The external point at times is very slow and takes more than 60 sec to respond. So, as a work around I implemented restTemplate
timeout(15s) but, how to implement circuit breaker techniques here. As a result of this my transaction is timing out (even after implementing timeout). Are there any solutions to overcome this out of box in spring-batch.
CodePudding user response:
how to implement circuit breaker techniques here
You can annotate the ItemProcessor#process
with @CircuitBreaker
(see attributes like maxAttempts
, resetTimeout
, etc) from the spring-retry library and add a recovery method that you annotate with @Recover
.
Michael Minella gives a complete sample of this very scenario in his talk: Cloud Native Batch Processing. And you can find the code example here.