Celery 工作人员之间共享 XMPP 连接
我的网络应用程序需要能够发送 XMPP 消息(Facebook 聊天),我认为 Celery 可能是一个很好的解决方案。任务包括查询数据库并将 XMPP 消息发送给多个用户。然而,使用这种方法,每次运行任务时我都必须连接到 XMPP 服务器,这不是一个好主意。
最佳实践
- 您的 Facebook Chat 集成只能用于预期长期存在的会话。客户不应快速流失。
有没有办法在工作人员之间共享 XMPP 连接,这样我就不必每次发送消息时都重新连接?或者,有更好的解决方案吗?
My web app needs to be able to send XMPP messages (Facebook Chat), and I thought Celery might be a good solution for this. A task would consist of querying the database and sending the XMPP message to a number of users. However, with that approach I would have to connect to the XMPP server every time I run a task, which is not a great idea.
From the Facebook Chat API docs:
Best Practices
- Your Facebook Chat integration should only be used for sessions that are expected to be long-lived. Clients should not rapidly churn on and off.
Is there a way to share an XMPP connection between workers so I don't have to reconnect every time I want to send a message? Or, is there a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 celery 任务模块中全局创建连接,并在任务中使用它来发送消息。在这种情况下,连接将在启动时建立,并将在工作进程之间共享。
You can create a connection globally in your celery task module and use it from your tasks to send messages. In that case the connection will be established at start-up and will be shared between worker processes.
一个长期运行的后台作业怎么样,它的工作是从其他短期进程接收消息并将它们推送到 XMPP 套接字上?
How about a long-running background job whose job it would be to receive messages from other short-lived processes and push them onto an XMPP socket?