Decoupled Message Queue Pattern for Login

126 views Asked by At

Let's say a user accesses a resource and it maps to a handler foo().

In foo() I want to check if the user's session is valid. For maximum decoupling (and for the sake of the example) I put the provided session ID into a message and push that into the queue VERIFY_SESSION where it is picked up by a subscribed worker. The worker takes the session ID out of the message, checks the database, etc and then adds some data indicating the session is valid to the message before pushing it to VERIFIED_SESSIONS.

Question: How do I get the information that the session is valid back into the worker that handles the user's connection?

If I subscribe all frontend workers to the queue VERIFIED_SESSIONS, there is no way of telling which worker will receive it. All I can think of would be to basically implement RPC on top of the message queue, but that would defeat the purpose of having the queue to begin with.

What is the common pattern here?

0

There are 0 answers