简体   繁体   中英

Combine two Stream into one Flux

How can I combine two streams Stream<String> into Flux ? What I understand is that I might need to use Flux create method to create this but I am not really sure about it:

flux1.create(sink -> {
    sink.onRequest(L -> {
        for(long l = 0; l < L; l++) {
            sink.next(..);
        }
    });
})

Please help.

Concat the Stream s into one and then invoke Flux#fromStream :

Flux<String> flux = Flux.fromStream(Stream.concat(stream1, stream2));

Another way of doing this would be to create a Flux using Flux#fromStream and then Flux#merge :

Flux<String> flux = Flux.merge(flux1, flux2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM