I'm running into an issue where @CircuitBreaker is not retrying.
I have a service class (ex. Class UserService and method name getUser), this method calls another Spring bean (ex. AppClient and execute) which in turn makes call to remote service(REST call). the execute method is annoted with @CircuitBreaker of Spring-Retry.
I have exposed the call to service method (Class UserService and method name getUser) in rest controller and I test it using Postman. here is what happens - In case of timeout error, it does call @Recover method. But it wouldn't retry calling the remote service three times (default value).
If I manually run it 3 times through Postman, the circuit breaker state changes to OPEN and redirects calls to @Recover method and after reset time out, it resumes making calls to remote service.
Also, I replaced @CircuitBreaker with @Retryable and that makes call three times (default value). I'm using spring-retry version 1.2.1.RELEASE and aspectjtools version 1.6.2.
Why would it not retry with @CircuitBreaker?? I would like to have both features Circuit breaker and Retry. As per Documentation @CircuitBreaker is suppose to do both. Any help would be appreciated.
@Configuration
@EnableRetry
public class cfgUserApp
{
}
@RestController
public class UserController
{
@Autowired
UserService userService;
@RequestMapping(value = "/user/{userId}", method = RequestMethod.GET, headers = "Accept=application/json")
public ResponseEntity<User> getUser(@PathVariable String userId) {
return ok(userService.getUser(userId));
}
}
/* Spring Bean -- userService */
public class UserServiceImpl
implements userService
{
@Override
public User getUser( final String userId )
{
checkArgument( User != null && !User.isEmpty(), "User Id can not be null or empty." );
try
{
final HttpGet request = buildGetUserRequest( userId );
final User userResult = appClient.execute( request,
response -> createGetReservationResult( response ) );
return userResult;
}
catch ( final IOException e )
{
LOG.error( "getUser failed.", e );
throw new AppException(e.getMessage(), e);
}
}
}
public Class Appclient {
@Recover
public <T> T recover(AppException appException, final HttpUriRequest request,
final ResponseHandler<T> responseFunction )
{
System.out.println("In Recovery");
return <T>new User();
}
@CircuitBreaker( include = AppException.class, openTimeout = 5000l, resetTimeout = 10000l )
public <T> T execute( final HttpUriRequest request,
final ResponseHandler<T> responseFunction )
{
// HTTP call
}
}