相关疑难解决方法(0)

How to iterate Flux and mix with Mono

I have a use case when I should send email to the users. First I create email body.

Mono<String> emailBody = ...cache();
Run Code Online (Sandbox Code Playgroud)

And then I select users and send the email to them:

Flux.fromIterable(userRepository.findAllByRole(Role.USER))
            .map(User::getEmail)
            .doOnNext(email -> sendEmail(email, emailBody.block(), massSendingSubject))
            .subscribe();
Run Code Online (Sandbox Code Playgroud)

What I don't like

  1. Without cache() method emailBody Mono calculates in each iteration step.
  2. To get emailBody value I use emailBody.block() but maybe there's a reactive way and not call block method inside Flux flow?

java reactive-programming project-reactor spring-webflux

2
推荐指数
1
解决办法
7205
查看次数