Im familiar with Spring Flux + SSE, tried to write some code that stream data.
Two issues here:
Flux.fromIterable
that emmits complete signal at the end of array.It closes commection for a some time (about 1 minute). Probably its timeout somewhere. Response should be cloused only when OnComplete
event fires.
@Controller("/")
@Validated
public class HelloController {
@Produces(MediaType.TEXT_EVENT_STREAM) // add 'application/stream+json'
@Get("/hello/{name}")
public Flux<Hello> hello(@NotBlank String name) {
List<Hello> list = new ArrayList<>();
list.add(new Hello("test1", 1));
list.add(new Hello("test2", 2));
return Flux.fromIterable(list).doOnComplete(() -> {
System.out.println("response should be closed here!");
});
}
}
-Also please add support for the application/stream+json
content-type
-And support server side events for a client via Flux.
As far as I am aware the content type application/stream+json is not an official media type. There is a draft attempting to registering this type but it relates to activity streams https://tools.ietf.org/id/draft-snell-activity-streams-type-01.html
Demonstrates your use case implemented with MediaType.APPLICATION_JSON_STREAM which is of type application/x-json-stream
As for why chrome keeps spinning this is because Micronaut implements keep alive and keeps the connection alive to satisfy further requests