22
22
import io .netty .handler .ssl .JdkSslContext ;
23
23
import io .netty .handler .timeout .ReadTimeoutHandler ;
24
24
import io .netty .handler .timeout .WriteTimeoutHandler ;
25
- import reactor .core .publisher .EmitterProcessor ;
26
25
import reactor .core .publisher .Flux ;
27
- import reactor .core .publisher .FluxSink ;
26
+ import reactor .core .publisher .FluxIdentityProcessor ;
28
27
import reactor .core .publisher .Mono ;
28
+ import reactor .core .publisher .Processors ;
29
+ import reactor .core .publisher .Sinks ;
29
30
import reactor .netty .http .client .HttpClient ;
30
31
import reactor .netty .transport .ProxyProvider ;
31
32
106
107
import org .elasticsearch .search .aggregations .Aggregation ;
107
108
import org .elasticsearch .search .suggest .Suggest ;
108
109
import org .reactivestreams .Publisher ;
110
+
109
111
import org .springframework .data .elasticsearch .client .ClientConfiguration ;
110
112
import org .springframework .data .elasticsearch .client .ClientLogger ;
111
113
import org .springframework .data .elasticsearch .client .ElasticsearchHost ;
@@ -465,12 +467,10 @@ public Flux<SearchHit> scroll(HttpHeaders headers, SearchRequest searchRequest)
465
467
searchRequest .scroll (scrollTimeout );
466
468
}
467
469
468
- EmitterProcessor <ActionRequest > outbound = EmitterProcessor .create (false );
469
- FluxSink <ActionRequest > request = outbound .sink ();
470
-
471
- EmitterProcessor <SearchResponse > inbound = EmitterProcessor .create (false );
470
+ Sinks .StandaloneFluxSink <ActionRequest > request = Sinks .unicast ();
471
+ FluxIdentityProcessor <SearchResponse > inbound = Processors .unicast ();
472
472
473
- Flux <SearchResponse > exchange = outbound . startWith ( searchRequest ).flatMap (it -> {
473
+ Flux <SearchResponse > exchange = request . asFlux ( ).flatMap (it -> {
474
474
475
475
if (it instanceof SearchRequest ) {
476
476
return sendRequest ((SearchRequest ) it , requestCreator .search (), SearchResponse .class , headers );
@@ -495,7 +495,7 @@ public Flux<SearchHit> scroll(HttpHeaders headers, SearchRequest searchRequest)
495
495
if (isEmpty (searchResponse .getHits ())) {
496
496
497
497
inbound .onComplete ();
498
- outbound . onComplete ();
498
+ request . complete ();
499
499
500
500
} else {
501
501
@@ -509,10 +509,13 @@ public Flux<SearchHit> scroll(HttpHeaders headers, SearchRequest searchRequest)
509
509
}).map (SearchResponse ::getHits ) //
510
510
.flatMap (Flux ::fromIterable );
511
511
512
- return searchHits .doOnSubscribe (ignore -> exchange .subscribe (inbound ));
512
+ return searchHits .doOnSubscribe (ignore -> {
513
+ exchange .subscribe (inbound );
514
+ request .next (searchRequest );
515
+ });
513
516
514
517
}, state -> cleanupScroll (headers , state ), //
515
- state -> cleanupScroll (headers , state ), //
518
+ ( state , ex ) -> cleanupScroll (headers , state ), //
516
519
state -> cleanupScroll (headers , state )); //
517
520
}
518
521
0 commit comments