I have enabled my application to use the actuator/health endpoint and kept getting the status as ‘DOWN’. After checking the full health endpoint details, I can see that I am getting two reponses for the redis health check, one for the reactive redis connection and one for the non-reactive redis connection. In our configuration class, we are only uisng the ReactiveRedisConnectionFactory class, so I wanted to try and see if there is a way to disable the non-reactive one / what others have done to get around this issue.
I did see the below thread, but it seemed more of a workaround, rather than actually looking into why there are two connections. – Spring Boot Reactive Redis 2 connection factories causing health check fail
@SneakyThrows
@Bean
public TrustManagerFactory trustManagerFactory() {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
InputStream certIS = new ByteArrayInputStream(serverCA.getBytes(StandardCharsets.UTF_8));
trustStore.setCertificateEntry("serverCA", CertificateFactory.getInstance("X509").generateCertificate(certIS));
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
return trustManagerFactory;
}
@Bean
public RedisStandaloneConfiguration redisStandaloneConfiguration() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisHost, redisPort);
redisStandaloneConfiguration.setPassword(redisPassword);
return redisStandaloneConfiguration;
}
@Bean
@Primary
public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory() {
SslOptions sslOptions = SslOptions.builder().trustManager(trustManagerFactory())
.jdkSslProvider()
.build();
ClientOptions clientOptions = ClientOptions.builder().sslOptions(sslOptions).build();
LettuceClientConfiguration.LettuceClientConfigurationBuilder clientConfigurationBuilder = LettuceClientConfiguration.builder();
LettuceClientConfiguration clientConfiguration = clientConfigurationBuilder
.clientOptions(clientOptions)
.useSsl()
.build();
return new LettuceConnectionFactory(redisStandaloneConfiguration(), clientConfiguration);
}
Health check results:
{
"status": "DOWN",
"components": {
"redis": {
"status": "DOWN",
"components": {
"reactiveRedisConnectionFactory": {
"status": "UP",
"details": {
"version": "7.0.14"
}
},
"redisConnectionFactory": {
"status": "DOWN",
"details": {
"error": "org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis"
}
}
}
},
}
}