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?
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:
- Random token generated by client
- The client sends the token, account and password to the server
- The server records the token in redis, but the login is not successful
- The server puts the token, account and password into the queue for processing
- Queue processing: if the account number is correct, the token in redis is marked as success, otherwise it is marked as failure
- 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.