I'm using Spring Webflux, Spring Data, and Project Reactor for non-blocking I/O (Spring Boot 2.0.0.M7).
My goal is to create a stock ticker-like API to allow a client to request all the resources from an endpoint based on some criteria, and also receive new resources that are created after the initial request. Reactive MongoDB is the backing store. The basic HandlerFunction
implementation looks like the below.
Mono<ServerResponse> getFoos(ServerRequest request) {
ok().contentType(TEXT_EVENT_STREAM)
.body(fooRepository.findAll(), Foo)
}
Obviously, this just returns all the Foos
that are currently available, then the Publisher
closes the connection and no new Foos
are sent to the client. My question is about what pattern to use to add an infinite stream to this which can accept new entries?
- Concat with some global
Publisher Bean
which I write newFoos
to as they are created - Add an
onComplete
which resubscribes to theRepository
(with some criteria to filter duplicate entries) - Use
repeat
and let the client filter the duplicates - Something else?