I can best describe what I’m looking for with an example of a simplified version. One of the demos for Tornado is a simple chat server:
https://github.com/facebook/tornado/blob/master/demos/chat/chatdemo.py
I’m interested in the MessageMixin class here. It keeps a static-length backlog of messages, and when new messages are available, it returns the slice of the message list that’s new. Or that’s what it appears to do. I know that I’ve implemented something like that before when writing a simple comet app.
So has anyone generalized this and added fancy things to it? I’m particularly interested in a way to manage many channels of communication and delete ones that haven’t been used in a while. Persistence might also be useful.
Is this something an MQ can do?
Redis has a publish/subscribe feature, along with additional data structure-oriented commands which you can use to persist and expire the message backlog, list users in a given room, or other attributes associated with them. The protocol is text-based and is a superset of the Memcached commands.
Here is a description which uses chat as an example of pub/sub along with a Ruby example using Websocket, and a snippet in Python which uses Websocket, Tornado and Redis pub/sub to implement a simple chat room.
Based on the information in your question, a dedicated message queue (like RabbitMQ) may also be useful to you. It is hard to say without knowing what you need in the areas of message volume, fault-tolerance, replication, etc. Redis may also be what you’re looking for, but if nothing else it is pretty simple and could help you get a prototype running quickly to further nail down your app’s requirements.