Comet 通过消息队列提供基于用户的通知

发布于 2024-09-06 18:09:43 字数 1016 浏览 0 评论 0原文

我们尝试构建应使用 Comet(AJAX 推送)向个人用户发送通知的应用程序。大多数通知的超时时间相当短。

当我们运行 RabbitMQ 时,通过 AMQP 发送消息是最简单的。我想知道解决个人用户问题的最佳方法是什么,以便 Comet 服务器和队列服务器都能轻松完成工作。

我查看了许多解决方案,包括使用 Carrot 与 Orbited、Tornado 等。

如果 Comet 服务器为每个用户注册一个消费者(在队列中),那么这些消费者要么必须超时保留,要么在每次使用后丢弃。这两种解决方案似乎都非常有希望。我想象这样的事情在 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()

或者,comet 服务器只能有一个队列消费者,并且必须实现自己的轻量级消息队列,该队列可以缓存传入的通知,直到用户连接并使用它们。这似乎是 memcached 可能有用的东西,但我没有这方面的经验。

这里最好的方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-09-13 18:09:43

我有几乎相同的用例,最终最终使用 Socket.IO 用于客户端,TornadIO 用于处理连接,RabbitMQ 用于消息传递(来自 鼠兔)。效果非常好,值得尝试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文