views:

55

answers:

0

We trying to build application that should use Comet (AJAX Push) to send notifications to individual users. Most notifications will have a fairly low timeout.

As we are running RabbitMQ, it would be easiest to send messages through AMQP. I am wondering what the best way to address individual users is, so that both the Comet server and the queue server have an easy job.

I have looked at a number of solutions including using Carrot with Orbited, Tornado, and more.

If the comet server registers one consumer (with the queue) for every user, then these consumers either have to be kept with a timeout, or discarded after every use. Neither solution seems very promising. I imagine something like this would be possible in Tornado/Carrot:

class MainHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
        user_id = 123

        consumer = Consumer(connection=conn, queue="feed", exchange="feed", routing_key=user_id)
        consumer.register_callback(self.message_received)
        consumer.wait()

    def message_received(self, message_data, message):
        self.write(simplejson.dumps(message_data))
        message.ack()
        consumer.close()

        self.finish()

Alternatively, the comet server could only have one consumer for the queue and have to implement its own lightweight message queue that can cache incoming notifications until a user connects and uses them. This seems like something that memcached might be good for, but I have no experience with it.

What would be the best approach here?