|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2017 the original author or authors. |
| 2 | + * Copyright 2012-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -46,19 +46,29 @@ public RedisReactiveHealthIndicator(
|
46 | 46 |
|
47 | 47 | @Override
|
48 | 48 | 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 | + } |
52 | 52 |
|
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()); |
57 | 63 | }
|
58 | 64 |
|
59 | 65 | private Health up(Health.Builder builder, Properties info) {
|
60 | 66 | return builder.up().withDetail(RedisHealthIndicator.VERSION,
|
61 | 67 | info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build();
|
62 | 68 | }
|
63 | 69 |
|
| 70 | + private Health down(Health.Builder builder, Throwable cause) { |
| 71 | + return builder.down(cause).build(); |
| 72 | + } |
| 73 | + |
64 | 74 | }
|
0 commit comments