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

[MU] Disconnection: the distributed way #5334

Open
chibenwa opened this issue Nov 20, 2024 · 4 comments · May be fixed by linagora/tmail-backend#1473
Open

[MU] Disconnection: the distributed way #5334

chibenwa opened this issue Nov 20, 2024 · 4 comments · May be fixed by linagora/tmail-backend#1473
Assignees

Comments

@chibenwa
Copy link
Member

chibenwa commented Nov 20, 2024

In a brand new server/data/data-rabbitmq implement a version of the DisconnectorNotifier leveraging a broadcast thus enabing to call disconnect endpoint only on a single node of the cluster.

Follow broadcast best practicces

  • Create one exchange fanout
  • Create one (quorum) queue per node based on a UUID
  • Use QUEUE-TTL
  • Monitor in a healthcheck the consumer and recreate it if missing.
  • Handle RabbitMQ reconnection

Cc @guimard

@chibenwa
Copy link
Member Author

Could we contribute this as part of tmail rather than as part of James?

@vttranlina
Copy link
Member

vttranlina commented Jan 15, 2025

I think we need to refactor DisconnectorNotifier first ,
Currently DisconnectorNotifier is using Predicate<Username> as input,
With "predicate" we can not serialize/deserialize it to rabbitmq message.

My suggestion: Define Request interface, and use it in place of Predicate<Username>
It looks like:

interface Request {

        String asString();
    }

    class MultipleUserRequest implements Request {
        private final List<Username> usernames;

        @Inject
        public MultipleUserRequest(List<Username> usernames) {
            this.usernames = usernames;
        }

        @Override
        public String asString() {
            return usernames.stream().map(Username::asString).collect(Collectors.joining(",", "[", "]"));
        }
    }

    class AllUsersRequest implements Request {
        @Override
        public String asString() {
            return "[]";
        }
    }

Then the InVMDisconnectorNotifier will looks like

class InVMDisconnectorNotifier implements DisconnectorNotifier {
        private final Disconnector disconnector;

        @Inject
        public InVMDisconnectorNotifier(Disconnector disconnector) {
            this.disconnector = disconnector;
        }

        @Override
        public void disconnect(Request request) {
            switch (request) {
                case MultipleUserRequest multipleUserRequest:
                    disconnector.disconnect(multipleUserRequest.usernames::contains);
                    break;
                case AllUsersRequest allUsersRequest:
                    disconnector.disconnect(username -> true);
                    break;
                default:
                    throw new IllegalStateException("Unexpected value: " + request);
            }
        }
    }

And

class RabbitMQDisconnectorNotifier implements DisconnectorNotifier {
        private final reactor.rabbitmq.Sender sender

        @Override
        public void disconnect(Request request) {
            sender.send(request.asString()....)
        }
    }

@chibenwa
Copy link
Member Author

Agree with this refactoring which would move the code toward a kind of sealed case class.

@vttranlina
Copy link
Member

vttranlina commented Jan 16, 2025

WIP linagora/tmail-backend#1473

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

Successfully merging a pull request may close this issue.

2 participants