Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAMES-4081 Implement MailToAllUsers mailet #2469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

quantranhong1999
Copy link
Contributor

No description provided.

Comment on lines +76 to +81
Flux<Flux<MailAddress>> recipientsBatches = Flux.from(usersRepository.listReactive())
.map(Throwing.function(Username::asMailAddress))
.window(batchSize);

Flux.merge(sendMailToFirstRecipientsBatchDirectly(mail, recipientsBatches),
sendMailToRemainingRecipientsBatchAsynchronously(mail, recipientsBatches))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we subscribe twice and the order might not be stable.

This means the first 100 items on the first subscriptions are not necessarily the ones of the next subscriptions.

How about:

Flux.from(usersRepository.listReactive())
            .map(Throwing.function(Username::asMailAddress))
            .window(batchSize);
            .index()
            .flatMap(tuple -> if (tuple.key() == 0) {
                return sendMailToFirstRecipientsBatchDirectly(mail, tuple.value());
            } else {
                return sendMailToRemainingRecipientsBatchAsynchronously(mail, tuple.value());
            }).then().block();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use Flux.concat as it would wait for the first Publisher to finish.

Or sendMailToFirstRecipientsBatchDirectly.then(sendMailToRemainingRecipientsBatchAsynchronously).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW recipientsBatches is a cold publisher so is it supposed to produce data isolated regardless of subscribers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but because it is subscribed twice data may defer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first call: a, b, c, d, e => send mail synchronously to a, b, c

second call d, e, b, a, c => send mail asynchrounously to a, c

  • We called twice the ldap
  • and we sent a, b, c, a, c and not a, b, c, d, e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants