DWQA QuestionsCategory: DatabaseSession cannot be used when the queue is executed asynchronously. Can the login still use the queue?
And the goddess. Mm-hmm asked 2 months ago

Session cannot be used when the queue is executed asynchronously. Can the login still use the queue? How to deal with the corresponding relationship between cookie and session?

1 Answers
oraoto answered 2 months ago

Can I still use queues?

Login is usually a synchronous process. Queue is not bad, but it will increase the complexity.
The synchronous login process is to read the database, judge whether the account password is correct, and set the session, which can be completed in an HTTP request.
To switch to asynchronous, I can only think of the following method:

  1. Random token generated by client
  2. The client sends the token, account and password to the server
  3. The server records the token in redis, but the login is not successful
  4. The server puts the token, account and password into the queue for processing
  5. Queue processing: if the account number is correct, the token in redis is marked as success, otherwise it is marked as failure
  6. In the process of server and queue processing, the client always uses another interface to poll to see whether the token login is successful. If it is successful, all subsequent requests will take the token, otherwise the client login fails.

Therefore, we should complete the synchronous login process as soon as possible, and put some operations (e-mail notification, etc.) needed after login into the queue, instead of putting the whole login process into the queue.