-
-
Save smaldini/a537f7a1f6b77d59b5d4 to your computer and use it in GitHub Desktop.
Scatter gather Async Flux example using #ProjectReactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an async message-passing Processor exposing a Flux API | |
TopicProcessor<String> sink = TopicProcessor.create(); | |
// Scatter Gather the input sequence | |
sink | |
.map(String::toUpperCase) | |
.flatMap(s -> | |
Mono.fromCallable(() -> someRepository.findOneByCategory(s)) | |
.timeout(Duration.ofSeconds(3), someRepository::fallback) | |
.subscribeOn(Schedulers.parallel()) | |
) | |
.subscribe(System.out::println); | |
// Sink values asynchronously | |
sink.onNext("Rx"); | |
sink.onNext("ReactiveStreams"); | |
sink.onNext("ReactiveStreamsCommons"); | |
sink.onNext("RingBuffer"); | |
//Shutdown and clean async resources | |
sink.onComplete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment