Created
February 9, 2020 16:22
-
-
Save dariodariodario/5926e97e0786995af1c806c8769c39ed to your computer and use it in GitHub Desktop.
Is this behaviour of retry and groupBy expected in Reactor?
This file contains hidden or 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
var flux = Flux.range(0, 10); | |
var errorDone = new AtomicBoolean(false); | |
var count = flux.groupBy(i -> i % 2).flatMap(groupedFlux -> { | |
if (groupedFlux.key() == 0) { | |
return groupedFlux.flatMap(x -> { | |
if (x == 4 && !errorDone.get()) { | |
errorDone.set(true); | |
return Mono.error(() -> new RuntimeException()); | |
} else { | |
return Mono.just(x); | |
} | |
}).retry(); | |
} else { | |
return groupedFlux; | |
} | |
}).count().block(); | |
System.out.println(count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue with this is that I would expect the sub flow to recover (because of the retry). But it won't. This will only work if I put retry() before the count(). In the latter situation the code prints 14... as I would have expected by putting the retry as you can see in the snippet...