Concurrent processing of project reactor's flux

Viewed 3910

I’m very new to project reactor or reactive programming at large so I'm probably doing something wrong. I’m struggling to build a flow that does the following:

Given a class Entity:

Entity {
    private Map<String, String> items;
    public Map<String, String> getItems() {
        return items;
    }
}
  1. read Entity from DB (ListenableFuture<Entity> readEntity())
  2. perform some parallel async processing on every item (boolean processItem(Map.Entry<String, String> item))
  3. when all finished call doneProcessing (void doneProcessing(boolean b))

Currently my code is:

handler = this;
Mono
    .fromFuture(readEntity())
    .doOnError(t -> {
        notifyError(“some err-msg” , t);
        return;
    })
    .doOnSuccess(e -> log.info("Got the Entity: " + e))
    .flatMap( e -> Flux.fromIterable(e.getItems().entrySet()))
    .all(handler::processItem)
    .consume(handler::doneProcessing);

The thing works, but the handler::processItem calls don’t run concurrently on all items. I tried using dispatchOn and publishOn with both io and async SchedulerGroup and with various parameters, but still the calls run serially on one thread. What am I doing wrong?

Apart, I’m sure that in general the above can be improved so any suggestion will be appreciated.

Thanks

1 Answers
Related