Ruby on Rails with Imap Idle for Multiple Accounts

Ruby on Rails with IMAP IDLE for multiple accounts

There is no need to spawn a new thread for each IMAP session. These can be done in a single thread.

Maintain an Array (or Hash) of all users and their IMAP sessions. Spawn a thread, in that thread, send IDLE keep-alive to each of the connections one after the other. Run the loop periodically. This will definitely give you far more concurrency than your current approach.

A long term approach will be to use EventMachine. That will allow using many IMAP connections in the same thread. If you are processing web requests in the same process, you should create a separate thread for Event Machine. This approach can provide you phenomenal concurrency. See https://github.com/ConradIrwin/em-imap for Eventmachine compatible IMAP library.

How to listen a huge number of IMAP folders of differnet accounts in one thread?

Use the JavaMail IdleManager.



Related Topics



Leave a reply



Submit