Created
July 26, 2021 01:43
-
-
Save isyufu/a859f309c96b534d6db7f5930c2f685c to your computer and use it in GitHub Desktop.
java reactor parallel execution by key
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
import java.util.Arrays; | |
import reactor.core.publisher.Flux; | |
import reactor.core.scheduler.Schedulers; | |
Flux.fromIterable(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)) | |
.groupBy(x -> x.hashCode() % 5) | |
.parallel(10) | |
.runOn(Schedulers.parallel()) | |
.flatMap(g -> g.collectMap(y -> {log.info(" g: "+g.key()+" y: "+ y); return y;}).log("subscr")) | |
.subscribe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment