Commit f790556f authored by Phillip Webb's avatar Phillip Webb

Polish 'Drop blocking RedisReactiveHealthIndicator calls'

See gh-16756
parent de857372
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -46,14 +46,20 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato ...@@ -46,14 +46,20 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
@Override @Override
protected Mono<Health> doHealthCheck(Health.Builder builder) { protected Mono<Health> doHealthCheck(Health.Builder builder) {
Mono<ReactiveRedisConnection> connection = Mono return getConnection()
.fromSupplier(this.connectionFactory::getReactiveConnection) .flatMap((connection) -> doHealthCheck(builder, connection));
.subscribeOn(Schedulers.parallel()); }
return connection private Mono<Health> doHealthCheck(Health.Builder builder,
.flatMap((c) -> c.serverCommands().info().map((info) -> up(builder, info)) ReactiveRedisConnection connection) {
.onErrorResume((e) -> Mono.just(builder.down(e).build())) return connection.serverCommands().info().map((info) -> up(builder, info))
.flatMap((signal) -> c.closeLater().thenReturn(signal))); .onErrorResume((ex) -> Mono.just(down(builder, ex)))
.flatMap((health) -> connection.closeLater().thenReturn(health));
}
private Mono<ReactiveRedisConnection> getConnection() {
return Mono.fromSupplier(this.connectionFactory::getReactiveConnection)
.subscribeOn(Schedulers.parallel());
} }
private Health up(Health.Builder builder, Properties info) { private Health up(Health.Builder builder, Properties info) {
...@@ -61,4 +67,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato ...@@ -61,4 +67,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build(); info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build();
} }
private Health down(Health.Builder builder, Throwable cause) {
return builder.down(cause).build();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment