Resilience4j version: 1.7.0 Java version: 8
I'm trying to retry a boolean method using Resilience4j if it returns a false. The code is as follows
@Retry(name = "redis")
public boolean publishMessage(RedisMessageWrapper redisMessage) {
try {
String response = redisCommands.set(redisMessage.getKey(), redisMessage.getValue());
logger.info("Response after publishing the message is {}", response);
return (RedisMessageUtils.SET_ACK_MSG.equalsIgnoreCase(response));
} catch (Exception e) {
logger.error("An error occurred while trying to publish the message", e);
return false;
}
}
I have created a customizer bean to retry on a false result.
@Bean
public RetryConfigCustomizer retryConfigCustomizer() {
return RetryConfigCustomizer
.of("redis", builder -> builder.retryOnResult(result -> (boolean) result == false));
}
My properties file has the following:
resilience4j.retry.configs.default.maxAttempts=3
resilience4j.retry.configs.default.retryExceptions[0]=org.springframework.web.client.HttpServerErrorException
resilience4j.retry.configs.default.retryExceptions[1]=java.util.concurrent.TimeoutException
resilience4j.retry.configs.default.retryExceptions[3]=org.springframework.web.client.ResourceAccessException
resilience4j.retry.configs.default.ignoreExceptions[0]=io.github.resilience4j.circuitbreaker.CallNotPermittedException
resilience4j.retry.configs.default.ignoreExceptions[1]=org.springframework.web.client.HttpClientErrorException
resilience4j.retry.instances.redis.baseConfig=default
resilience4j.retry.instances.redis.waitDuration=3500
I have other retries and circuit breakers configured in the project that work fine since they work with exceptions, but in this case since I'm dealing with a boolean, I'm lost as to why my implementation doesn't work. Any help would be appreciated.