I'm trying to test streaming a Flux with a delay of 1000 millis for each element.
@Get(value = "/carts/reactive", produces = MediaType.APPLICATION_JSON_STREAM)
public Flux<Cart> getCartsReactive() {
return Flux.range(1, 10)
.map(integer -> Cart.builder().name("cart" + integer).build())
.delayElements(Duration.ofMillis(1000))
.doOnNext(cart -> log.info("Returning Flux of cart: " +cart));
}
When I hit the service, I don't get a response for 10 seconds and get a blog of response.
curl http://localhost:7070/carts/reactive
{"name":"cart1"}{"name":"cart2"}{"name":"cart3"}{"name":"cart4"}{"name":"cart5"}{"name":"cart6"}{"name":"cart7"}{"name":"cart8"}{"name":"cart9"}{"name":"cart10"}
Is this a bug? Why doesn't it emit 1 cart every second?