实时 ruby​​ 应用程序:CRAMP 与 NODE.JS

发布于 2024-09-01 00:00:02 字数 42 浏览 2 评论 0 原文

我想知道你们中是否有人知道哪一个更好,以及使用其中之一时应考虑哪些因素

I was wondering if any of you had insights about which one is better, and what factors should be taken into consideration when using one of these

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

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

发布评论

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

评论(5

帅的被狗咬 2024-09-08 00:00:03

我可以从另一面(Node.js)多讲一些。我刚刚编写了一个与 Rails 3 集成的 gem,它使用 Node.js 后端来监听 Redis PUBSUB 消息并相应地更新 Rails 前端。

Socket.IO + Node 与 Rails 应用程序集成并不难(特别是使用 jQuery 时),但根据您的目标浏览器基础(如 IE7),在所有情况下都能正常工作可能会很棘手,即因为某些原因使用 Flash Socket 作为后备时的奇怪情况(通常在 WebSocket 不起作用的情况下)。

也就是说,我强烈推荐 Node.js + Socket.IO。它是超轻量级的,有很多选项和灵活性,可以扩展来做几乎任何你想做的事情。在我看来,Rails 是一个非常棒的 Web 框架,用于构建需要计算量大的前端的更大应用程序。我不会选择将它用于小型事件驱动应用程序,因为它单独为框架使用了太多内存。我喜欢 Ruby/Rails,但是当需要快速、干净的事件处理/消息处理时,我会选择 Node。

如果您需要更具体的示例,我的项目 Kthxbye(一个 Resque 风格的克隆)与 Redis 通信,而 Node.JS 又会监听 Redis,而 Node.JS 又可以更新 Web 应用程序。

插件http://github.com/plukevdh/kthxbye(请参阅: http://github.com/plukevdh /kthxbye/blob/master/lib/generators/kthxbye/templates/kthxbye.js)

节点后端http://github.com/plukevdh/kthxbye-node (参见:http://github.com/plukevdh/kthxbye-node/blob/master/poll.js

(对于节点上完全缺乏文档表示歉意项目。)

I can speak more from the other (Node.js) side. I just wrote a gem that integrates with Rails 3 that uses a Node.js back-end for listening to Redis PUBSUB messages and updates the Rails front-end accordingly.

Socket.IO + Node is not hard to integrate with a Rails app (especially if working with jQuery), but depending on your targeted browser base (like IE7), it can be tricky to get working right in all cases, namely because of some weird cases when using Flash Socket as a fallback (usually where WebSockets don't work).

That said, I highly recommend Node.js + Socket.IO. It is super light-weight with a lot of options and flexibility to extend to do almost anything you could want. In my opinion, Rails is a fantastic web framework for building bigger apps that need a computationally heavy front-end. I would not choose to use it for small, event driven applications simply because it uses so much memory for the framework alone. I love Ruby/Rails, but when it comes to needing something for quick and clean event processing/message handling, Node has my vote.

If you need more concrete examples, my project Kthxbye (a Resque-esque clone) communicates with Redis which in turn is listened to by Node.JS which in turn can update a web application.

Plugin: http://github.com/plukevdh/kthxbye (see: http://github.com/plukevdh/kthxbye/blob/master/lib/generators/kthxbye/templates/kthxbye.js)

Node Backend: http://github.com/plukevdh/kthxbye-node (see: http://github.com/plukevdh/kthxbye-node/blob/master/poll.js)

(Apologies for the complete lack of documentation on the node project.)

我ぃ本無心為│何有愛 2024-09-08 00:00:03

不久前我玩过《cramp》和《rails 3》。正在尝试使用 WebSockets 构建一个具有动态更新的视图,以便在客户端和服务器之间来回传输数据。它与 Chrome 完美配合,但 Safari 5 和 FF 实现了更新版本的 websocket 协议,而 Cramp 则没有,所以我无法让它在那里工作。

我同意在整个堆栈中使用 Ruby 很好,但我发现 Cramp 现在在某些方面稍微落后于曲线。

我决定硬着头皮使用 node.js (和 SocketIO 包)来完成我的工作。

祝你好运!

I played around with cramp and rails 3 a while back. Was trying to build a view with dynamic updates using WebSockets to channel data back and forth between clients and the server. It worked perfectly with Chrome, but Safari 5 and FF implement a more recent version of the websocket protocol and Cramp does not so I couldn't get it to work there.

I agree that using Ruby for the whole stack is nice, but I feat that Cramp right now is lagging slightly behind the curve in some aspects.

I decided to bite the bullet and use node.js (and the SocketIO package) for my stuff.

Good luck!

嘿咻 2024-09-08 00:00:03

我现在正在使用 Rails (3) 和 Cramp 一起编写一个不简单的 Web 应用程序。我没有任何 Node.js 经验,而且我才刚刚开始使用 Cramp,但它看起来很有前途。在我看来,能够使用 Ruby 是一个很大的优势! (我从 Tornado (Python) 开始,无法忍受这种语言。对不起 Python 粉丝!)

缺点是我在 Cramp 上发现的第三方材料非常非常少。我想考虑到它是多么新,这并不奇怪,但你或多或少要靠自己。如果您需要手持,您可能不应该使用 Cramp。

I'm writing a somewhat non-trivial web app using Rails (3) and Cramp together at the moment. I don't have any experience with Node.js, and I only just started using Cramp as it is, but it looks promising. And in my opinion, being able to use Ruby is a big plus! (I started with Tornado (Python) and couldn't bear the language. Sorry Python fans!)

The downside is that I have found very, very little third-party material on Cramp. I guess that's not surprising considering how new it is, but you're more or less on your own. If you need your hand held, you probably shouldn't use Cramp.

暗喜 2024-09-08 00:00:03

查看不同的痉挛存储库。 WebSocket 是移动目标,生活在边缘并不那么容易。
github.com/maccman/cramp fork 适用于最近的 websockets 实现,而原始的cramp 不是最新的并且正在重构。另请查看 eventmachine-websockets。不管怎样——准备好在服务器端使用thin+eventmachine。有了抽筋,你应该在生产模式下瘦身,抽筋还没有那么好。

Check out different repos of cramp. WebSockets are moving target, and living on the edge isn't that easy.
github.com/maccman/cramp fork works with rescent websockets implementation, while original cramp is not up to date and under refactoring. Also take a look at eventmachine-websockets. Anyway - be prepeared to use thin+eventmachine on serverside. With cramp you should run thin in production mode , cramp is not that good yet.

拒绝两难 2024-09-08 00:00:03

为什么你要把自己限制在红宝石一侧的 Cramp 上?

您还可以通过 websocket-rails 将 Rails 用于实时应用程序。

您还可以使用实时框架,例如 PleziVolt...在我看来,Volt 和 Plezi 都比 Cramp 工作得更好(但我有偏见,因为我编写了 Plezi 框架)。

这是一个带有 Plezi 的简单 echo websocket 服务器:

require 'plezi'

class EchoCtrl
    def index
        redirect_to 'http://www.websocket.org/echo.html'
    end
    def on_message data
        # to broadcast the data add:
        # broadcast :_send_message, data
        _send_message data
    end
    def _send_message data
        response << data
    end
end

listen 

# you can add, a socket.io route for JSON with socket.io
route '/socket.io', EchoCtrl
route '/', EchoCtrl

# exit the irb console to finish the setup and start the Plezi server
exit

Why are you limiting yourself to Cramp on the ruby side?

You can use Rails also for real-time apps with websocket-rails.

You could also use real-time frameworks such as Plezi or Volt... both Volt and Plezi work better than Cramp, in my opinion (but I'm biased, as I wrote the Plezi framework).

Here is a simple echo websocket server with Plezi:

require 'plezi'

class EchoCtrl
    def index
        redirect_to 'http://www.websocket.org/echo.html'
    end
    def on_message data
        # to broadcast the data add:
        # broadcast :_send_message, data
        _send_message data
    end
    def _send_message data
        response << data
    end
end

listen 

# you can add, a socket.io route for JSON with socket.io
route '/socket.io', EchoCtrl
route '/', EchoCtrl

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