I'm trying to implement a reactive, in-memory repository. How should this be accomplished?
This is a blocking version of what I'm trying to do
@Repository
@AllArgsConstructor
public class InMemEventRepository implements EventRepository {
private final List<Event> events;
@Override
public void save(final Mono<Event> event) {
events.add(event.block());
// event.subscribe(events::add); <- does not do anything
}
@Override
public Flux<Event> findAll() {
return Flux.fromIterable(events);
}
}
I tried using event.subscribe(events::add);
but the event was not added to the list (perhaps I'm missing something there?)
Perhaps events
should be of type Flux<Event>
and there is some way to add the Mono<Event>
to Flux<Event>
?