With reference to my previous question Splitting a WebClient Post of a Streaming Flux into JSON Arrays , I was using;
myFlux
.window(5)
.flatMap(window -> client
.post()
.body(window, myClass.class)
.exchange()
.flatMap(response -> response.bodyToMono)
)
.subscribe();
This works fine. However, on a slow day, 5 messages make take a while to arrive and the window
will not send anything until the window
is full. So
I switched to windowTimeout(5, Duration.ofSeconds(5))
.
Now, if there is no data and the Duration
is exceeded, the code is propagating an empty window
which is causing an empty array to be posted.
How do I detect an empty window
and not run the post
?