15
15
*/
16
16
package org .springframework .data .elasticsearch .client .reactive ;
17
17
18
- import org .springframework .http .HttpHeaders ;
19
18
import reactor .core .publisher .Mono ;
20
19
21
20
import java .net .InetSocketAddress ;
25
24
import org .springframework .data .elasticsearch .client .ElasticsearchHost ;
26
25
import org .springframework .data .elasticsearch .client .ElasticsearchHost .State ;
27
26
import org .springframework .data .elasticsearch .client .NoReachableHostException ;
27
+ import org .springframework .http .HttpHeaders ;
28
28
import org .springframework .web .reactive .function .client .WebClient ;
29
29
30
30
/**
@@ -60,20 +60,20 @@ public Mono<ClusterInformation> clusterInfo() {
60
60
.head ().uri ("/" )
61
61
.headers (httpHeaders -> httpHeaders .addAll (headersSupplier .get ())) //
62
62
.exchange () //
63
- .flatMap (it -> {
63
+ .map (it -> {
64
64
if (it .statusCode ().isError ()) {
65
65
state = ElasticsearchHost .offline (endpoint );
66
66
} else {
67
67
state = ElasticsearchHost .online (endpoint );
68
68
}
69
- return Mono . just ( state ) ;
69
+ return state ;
70
70
}).onErrorResume (throwable -> {
71
71
72
72
state = ElasticsearchHost .offline (endpoint );
73
73
clientProvider .getErrorListener ().accept (throwable );
74
74
return Mono .just (state );
75
75
}) //
76
- .flatMap (it -> Mono . just ( new ClusterInformation (Collections .singleton (it ) )));
76
+ .map (it -> new ClusterInformation (Collections .singleton (it )));
77
77
}
78
78
79
79
/*
@@ -96,14 +96,16 @@ public Mono<InetSocketAddress> lookupActiveHost(Verification verification) {
96
96
return Mono .just (endpoint );
97
97
}
98
98
99
- return clusterInfo ().flatMap ( it -> {
99
+ return clusterInfo ().handle (( information , sink ) -> {
100
100
101
- ElasticsearchHost host = it .getNodes ().iterator ().next ();
101
+ ElasticsearchHost host = information .getNodes ().iterator ().next ();
102
102
if (host .isOnline ()) {
103
- return Mono .just (host .getEndpoint ());
103
+
104
+ sink .next (host .getEndpoint ());
105
+ return ;
104
106
}
105
107
106
- return Mono .error (() -> new NoReachableHostException (Collections .singleton (host )));
108
+ sink .error (new NoReachableHostException (Collections .singleton (host )));
107
109
});
108
110
}
109
111
0 commit comments