在Rails应用程序和Node.js应用程序之间进行通信 [英] Communicate between a Rails app and a Node.js app

查看:110
本文介绍了在Rails应用程序和Node.js应用程序之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题遵循前一个问题:我应该使用Node.js而不是Rails用于实时WebApps吗?

This question follows a previous one: Shall I use Node.js Instead of Rails for Real-time WebApps?

问题:

在Rails应用程序和Node.js应用程序之间进行通信的最佳方式是什么才能利用这两种技术?

What's the best way of communicating between a Rails app and a Node.js app in order to take advantage of both technologies?

谢谢

推荐答案

为什么应用需要沟通?

如果你只需要一个Rails应用程序来获取浏览器中的实时数据,那么使用node.js服务器应用程序和Socket.IO就足够了。

If you simply need a Rails app to get some realtime data into the browser, then using a node.js server app and Socket.IO would be sufficient.

您必须记住,任何Rails应用程序实际上是两个应用程序,一个是在服务器上运行的Ruby编写的,另一个是在客户端上运行的Javascript编写的。它们通常通过HTTP进行通信,有时使用AJAX进行通信,有时则不通您的应用的哪个部分需要node.js的功能?

You have to remember that any Rails apps, is actually two applications, one written in Ruby running on the server, and one written in Javascript running on the client. They usually communicate over HTTP, sometimes with AJAX and sometimes not. Which part of your app needs the functionality of node.js?

如果是应用处理登录的情况,则显示网页,然后不断刷新那个带有实时数据的网页,你真的从node.js中获得了实时数据刷新的好处,无论你是用AJAX轮询还是用Websockets做的。共享数据库是应用程序进行通信的好方法,但不是实时的。

If it is the case that the app deals with login, then displays a web page, and then continually refreshes that web page with real-time data, you only really get a benefit from node.js for the realtime data refreshes whether you do it with AJAX polling or with Websockets. Shared databases are a nice way for apps to communicate, but not for realtime.

为了说清楚,如果你是Ruby with Rails的专家,你会更多如果您添加节点,js服务器应用程序并且仅将其用于高容量数据(例如实时更新),则会高效。然后,您可以使用混合Web应用程序,充分利用两种平台的优势。

To make it clear, if you are an expert in Ruby with Rails, you will be more productive if you add a node,js server app and only use it for high-volume data, such as realtime updates. You then have a hybrid web app that leverages the best of both platforms.

这篇关于在Rails应用程序和Node.js应用程序之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆