Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dariodariodario/5926e97e0786995af1c806c8769c39ed to your computer and use it in GitHub Desktop.
Save dariodariodario/5926e97e0786995af1c806c8769c39ed to your computer and use it in GitHub Desktop.
Is this behaviour of retry and groupBy expected in Reactor?
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);
@dariodariodario
Copy link
Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment