Python 彗星服务器

发布于 2024-07-22 14:13:25 字数 284 浏览 16 评论 0原文

我正在构建一个具有实时提要(类似于 Facebook 的新闻提要)的 Web 应用程序,我想通过长轮询机制对其进行更新。 据我所知,对于 Python,我的选择几乎是使用 Stackless(从他们的 Comet wsgi 示例构建)或 Cometd + Twisted。 不幸的是,关于这些选项的文档很少,而且我无法在网上找到有关 Python 上的 comet 生产规模用户的良好信息。

有人在生产系统中成功地在 Python 上实现了 comet 吗? 您是如何着手做到这一点的?我在哪里可以找到资源来实现我自己的?

I am building a web application that has a real-time feed (similar to Facebook's newsfeed) that I want to update via a long-polling mechanism. I understand that with Python, my choices are pretty much to either use Stackless (building from their Comet wsgi example) or Cometd + Twisted. Unfortunately there is very little documentation regarding these options and I cannot find good information online about production scale users of comet on Python.

Has anyone successfully implemented comet on Python in a production system? How did you go about doing it and where can I find resources to implement my own?

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

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

发布评论

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

评论(7

感情洁癖 2024-07-29 14:13:25

Orbited 似乎是一个不错的解决方案。 不过还没试过。


更新:过去 2.5 年里情况发生了变化。

现在,除了 IE(自然)和一些浏览器之外,我们在所有主要浏览器中都拥有 Websockets对它的非常好的抽象,提供了许多模拟实时通信的方法。

Orbited seems as a nice solution. Haven't tried it though.


Update: things have changed in the last 2.5 years.

We now have websockets in all major browsers, except IE (naturally) and a couple of very good abstractions over it, that provide many methods of emulating real-time communication.

半枫 2024-07-29 14:13:25

我建议您应该使用 StreamHub Comet Server - 它被很多人使用 - 我个人将它与我运行的几个 Django 网站。 您需要编写一点 Java 来处理流 - 我使用 Jython 来完成此操作。 前端代码是一些真正简单的 Javascript:

StreamHub hub = new StreamHub();
hub.connect("http://myserver.com/");
hub.subscribe("newsfeed", function(sTopic, oData) { alert("new news item: " + oData.Title); });

文档非常好 - 当您尝试开始使用 Cometd 等人的稀疏文档时,我遇到了类似的问题。 首先,我阅读了 Comet 入门和StreamHub,下载并查看一些示例的工作原理,并在需要时参考 API 文档:

I recommend you should use StreamHub Comet Server - its used by a lot of people - personally I use it with a couple of Django sites I run. You will need to write a tiny bit of Java to handle the streaming - I did this using Jython. The front-end code is some real simple Javascript a la:

StreamHub hub = new StreamHub();
hub.connect("http://myserver.com/");
hub.subscribe("newsfeed", function(sTopic, oData) { alert("new news item: " + oData.Title); });

The documentation is pretty good - I had similar problems as you trying to get started with the sparse docs of Cometd et al. For a start I'd read Getting Started With Comet and StreamHub, download and see how some of the examples work and reference the API docs if you need to:

尽揽少女心 2024-07-29 14:13:25

以下是结合 Django、Orbited 和 Twisted 创建实时 (Comet) 应用程序的全功能示例:http使用 Python 的://github.com/clemesha/hotdot

Here is a full-featured example of combining Django, Orbited,and Twisted to create a real-time (Comet) app: http://github.com/clemesha/hotdot using Python.

你怎么这么可爱啊 2024-07-29 14:13:25

我已经使用twisted完成了大量的API,其中大部分都可以在我的github帐户上找到。

大多数是客户端,但 slosh 是我编写的一个服务器,用于执行实时廉价的 pubsub 之类的事情。 通过允许简单的流复制,它可以在一定程度上水平扩展读取。 当您坚持使用纯 HTTP 时,写入会略有不同,但我已经通过它进行了相当多的演示以进行演示。

否则,您将拥有大多数 XMPP 服务器支持的完整 BOSH,并且允许您将消息分发与 Web 前端解耦。

I've done tons of APIs using twisted for stuff like that, most of which are available on my github account.

Most are client-side, but slosh is a server I wrote to do a realtime cheap pubsub sort of thing. It scales somewhat horizontally for reads by allowing for simple stream replication. Writes are a little different when you stick to plain HTTP, but I've pushed a decent amount through it for a demo.

Otherwise, you have full-on BOSH which most XMPP servers support and will allow you to decouple the message distribution from the web frontend.

御弟哥哥 2024-07-29 14:13:25

我还没做过,但是这个家伙 已经写了一篇关于它的好文章,其中包含 Django 示例和指向其他框架的指针(我尚未检查)。

I haven't done it, but this guy has and writes a good article about it, with Django examples and pointers (which I haven't checked) to other frameworks.

左耳近心 2024-07-29 14:13:25

Orbited 和 Redis 解决方案很好,但当你有像 google 发布的 PubSubHubbub 这样的东西时就不再相关了。 这使得成为给定提要的发布者或订阅者变得非常容易。 http://code.google.com/p/pubsubhubbub/

the orbited and redis solutions are nice, but not longer relevant when you have something like the PubSubHubbub that google released. This makes it very easy to be the publisher or the subscriber to a given feed. http://code.google.com/p/pubsubhubbub/

静谧 2024-07-29 14:13:25

这是一个执行 long- 的示例使用 gevent 和 Django 进行轮询

它使用 greenlet - 来自 Stackless 的堆栈切换功能,打包为 CPython 扩展。

Here's an example that does long-polling with gevent and Django.

It uses greenlet - stack switching functionality from Stackless packaged as a CPython extension.

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