Skip to content

Commit f790556

Browse files
committed
Polish 'Drop blocking RedisReactiveHealthIndicator calls'
See gh-16756
1 parent de85737 commit f790556

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,19 +46,29 @@ public RedisReactiveHealthIndicator(
4646

4747
@Override
4848
protected Mono<Health> doHealthCheck(Health.Builder builder) {
49-
Mono<ReactiveRedisConnection> connection = Mono
50-
.fromSupplier(this.connectionFactory::getReactiveConnection)
51-
.subscribeOn(Schedulers.parallel());
49+
return getConnection()
50+
.flatMap((connection) -> doHealthCheck(builder, connection));
51+
}
5252

53-
return connection
54-
.flatMap((c) -> c.serverCommands().info().map((info) -> up(builder, info))
55-
.onErrorResume((e) -> Mono.just(builder.down(e).build()))
56-
.flatMap((signal) -> c.closeLater().thenReturn(signal)));
53+
private Mono<Health> doHealthCheck(Health.Builder builder,
54+
ReactiveRedisConnection connection) {
55+
return connection.serverCommands().info().map((info) -> up(builder, info))
56+
.onErrorResume((ex) -> Mono.just(down(builder, ex)))
57+
.flatMap((health) -> connection.closeLater().thenReturn(health));
58+
}
59+
60+
private Mono<ReactiveRedisConnection> getConnection() {
61+
return Mono.fromSupplier(this.connectionFactory::getReactiveConnection)
62+
.subscribeOn(Schedulers.parallel());
5763
}
5864

5965
private Health up(Health.Builder builder, Properties info) {
6066
return builder.up().withDetail(RedisHealthIndicator.VERSION,
6167
info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build();
6268
}
6369

70+
private Health down(Health.Builder builder, Throwable cause) {
71+
return builder.down(cause).build();
72+
}
73+
6474
}

0 commit comments

Comments
 (0)