开发者

Comet for User based Notification over a Message Queue

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.du开发者_运维知识库mps(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?


I had almost the same use case and eventually ended up with Socket.IO for client-side, TornadIO for handling connections and RabbitMQ for message passing (via pika). Works quite well, worth to try it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜