node.js RabbitMQ 与 Socket.io?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6636213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RabbitMQ vs Socket.io?
提问by ajsie
I'm doing real time live web app development.
我正在做实时网络应用程序开发。
Browser users should be able to communicate with eachother through a node.js server. One of the user writes a message and all other users will get it.
浏览器用户应该能够通过 node.js 服务器相互通信。其中一个用户写了一条消息,所有其他用户都会收到它。
I don't quite get how RabbitMQ works. But from quick reading it seems that it handles publication/subscription of messages.
我不太明白 RabbitMQ 是如何工作的。但是从快速阅读来看,它似乎处理消息的发布/订阅。
A user (in a browser) publishes something and subscribers (in other browsers) get that message. Isn't that what Socket.io is doing with websockets?
用户(在浏览器中)发布某些内容,而订阅者(在其他浏览器中)会收到该消息。这不是 Socket.io 对 websockets 所做的事情吗?
Here are my questions:
以下是我的问题:
- What are the advantages/disadvantages for each one of them?
- Can Socket.io replace RabbitMQ?
- Are there scenarios I need RabbitMQ for web apps where Socket.io doesn't suffice?
- 他们每个人的优点/缺点是什么?
- Socket.io 可以代替 RabbitMQ 吗?
- 有没有我需要 RabbitMQ 来处理 Socket.io 不够用的 Web 应用程序的情况?
回答by Alfred
Update
更新
Are there scenarios I need RabbitMQ for web apps where Socket.io doesn't suffice? Browser users should be able to communicate with eachother through a node.js server. One of the user writes a message and all other users will get it.
是否存在我需要 RabbitMQ 用于 Socket.io 无法满足的 Web 应用程序的情况?浏览器用户应该能够通过 node.js 服务器相互通信。其中一个用户写了一条消息,所有其他用户都会收到它。
When you only have these simple requirements then socket.io alone will be enough.. You only need a message queuewhen you want to process your jobs(heavy) offline and in a controlled manner.
当你只有这些简单的需求时,socket.io 就足够了。. 当您希望以受控方式离线处理(繁重)作业时,您只需要一个消息队列。
http://en.wikipedia.org/wiki/Message_queue:
http://en.wikipedia.org/wiki/Message_queue:
Message queues provide an asynchronous communications protocol, meaning that the sender and receiver of the message do not need to interact with the message queue at the same time.
消息队列提供异步通信协议,意味着消息的发送方和接收方不需要同时与消息队列交互。
This sentence needs to sink in. The producer (one process) puts a job into the queue and the consumer consumes by taking the job from the queue. The consumer, most times, are multiple processes that consume multiple jobs concurrently. The consumer are unable to tell from each other, what jobs they are consuming.
这句话需要下沉。生产者(一个进程)将一个作业放入队列,消费者通过从队列中取出作业进行消费。大多数情况下,消费者是同时消费多个作业的多个进程。消费者无法相互分辨,他们正在消费什么工作。
This makes the queue a First-In-First-Out (FIFO) data structure.
这使队列成为先进先出 (FIFO) 数据结构。
That's I think an important property of the queue. The First-In-First-Out property although with an advanced message queue like beanstalkd you can give jobs priorities.
我认为这是队列的一个重要属性。先进先出属性虽然使用像 beanstalkd 这样的高级消息队列,但您可以指定作业优先级。
I hope this makes any sense at all ;)
我希望这有任何意义;)
I'm doing real time live web app development.
我正在做实时网络应用程序开发。
Could you explain a little better so that we can give you a better answer?
你能解释得更好一点,以便我们给你更好的答案吗?
I don't quite get how RabbitMQ works. But from quick reading it seems that it handles publication/subscription of messages.
我不太明白 RabbitMQ 是如何工作的。但是从快速阅读来看,它似乎处理消息的发布/订阅。
See the quote about message queue below. Let it sink in for a while. You could also read the WIKI about message queues.
请参阅下面有关消息队列的引用。让它沉入一段时间。您还可以阅读有关消息队列的 WIKI 。
A user (in a browser) publishes something and subscribers (in other browsers) get that message. Isn't that what Socket.io is doing with websockets?
用户(在浏览器中)发布某些内容,而订阅者(在其他浏览器中)会收到该消息。这不是 Socket.io 对 websockets 所做的事情吗?
Socket.io supports a lot of different transports(also websockets) and it should because websockets are not supported by the most browsers. But for example Google Chrome does already support websockets. I believe that websockets are the transport of the future(but not yet!). When you look at Socket.io's browser support pageyou will notice that Socket.io does support all the major browsers(some even ancient). The nice thing is that it wraps this around a nice API.
Socket.io 支持许多不同的传输(也包括 websockets),因为大多数浏览器不支持 websockets。但例如谷歌浏览器已经支持 websockets。我相信 websockets 是未来的交通工具(但还不是!)。当您查看Socket.io 的浏览器支持页面时,您会注意到 Socket.io 确实支持所有主要浏览器(有些甚至是古老的)。好消息是它围绕一个很好的 API 进行了包装。
What are the advantages/disadvantages for each one of them?
他们每个人的优点/缺点是什么?
You are comparing apples to oranges so comparing that is kind of strange.
你在比较苹果和橘子,所以比较有点奇怪。
RabbitMQ
兔MQ
http://www.rabbitmq.com/tutorials/tutorial-one-python.html:
http://www.rabbitmq.com/tutorials/tutorial-one-python.html:
RabbitMQ is a message broker. The principal idea is pretty simple: it accepts and forwards messages. You can think about it as a post office: when you send mail to the post box you're pretty sure that Mr. Postman will eventually deliver the mail to your recipient. Using this metaphor RabbitMQ is a post box, a post office and a postman.
RabbitMQ 是一个消息代理。主要思想非常简单:它接受并转发消息。您可以将其视为邮局:当您将邮件发送到邮箱时,您非常确定邮递员先生最终会将邮件递送给您的收件人。使用这个比喻,RabbitMQ 是一个邮箱、一个邮局和一个邮递员。
Advantages
好处
- It is a pretty good message queue. Personally I would use redisor beanstalkd.
- 它是一个相当不错的消息队列。我个人会使用redis或beanstalkd。
Disadvantages:
缺点:
- Is not really for "browsers".
- 并不是真正适用于“浏览器”。
Socket.io
Socket.io
Socket.IO aims to make realtime apps possible in every browserand mobile device, blurring the differences between the different transport mechanisms.
Socket.IO 旨在使每个浏览器和移动设备中的实时应用程序成为可能,模糊不同传输机制之间的差异。
Advantages
好处
- It is for browser
- 它适用于浏览器
Disadvantages
缺点
- It is not a message queue.
- 它不是消息队列。
Can Socket.io replace RabbitMQ?
Socket.io 可以代替 RabbitMQ 吗?
No you can't because they are two completely different things. You are comparing apples to oranges. You should try to comprehend both descriptions from the sites I quoted.
不,你不能,因为它们是两个完全不同的东西。您正在将苹果与橙子进行比较。您应该尝试从我引用的网站中理解这两种描述。
回答by sgtz
RabbitMQ is a really flexibly way of creating network topologies. It's mature, supported, and comes from a finance space (in finance they've been doing messaging for a long long time). I use RabbitMQ server-side, and use other protocols to connect to RabbitMQ over a "gateway".
RabbitMQ 是一种非常灵活的创建网络拓扑的方式。它是成熟的、受支持的,并且来自金融领域(在金融领域,他们已经做了很长时间的消息传递)。我使用 RabbitMQ 服务器端,并使用其他协议通过“网关”连接到 RabbitMQ。
Behind the scenes, RabbitMQ is written in an ultra concise functional language called Erlang. That's no big deal in and of itself, but the contention is that if you know what you are doing, and can say it in less lines of code, then it's ultimately more reliable and testable.
在幕后,RabbitMQ 是用一种名为 Erlang 的超简洁函数式语言编写的。这本身没什么大不了的,但争论是如果你知道你在做什么,并且可以用更少的代码行说出来,那么它最终会更可靠和可测试。
btw: Erlang is used by Facebook and Twitter for their behind the scenes stuff.
顺便说一句:Erlang 被 Facebook 和 Twitter 用于他们的幕后工作。
Now, RabbitMQ is more than just a network sockets type thing... it's based on "guaranteed delivery". That feature is important for enterprise situations. RabbitMQ, alternatively could be used to scale... actually, there's more than that... I'm not doing it justice.
现在,RabbitMQ 不仅仅是网络套接字类型的东西……它基于“保证交付”。该功能对于企业情况很重要。RabbitMQ,或者可以用来扩展......实际上,还有更多......我不是在做正义。
I can't comment on node.js as I haven't had a chance to play with it yet. I'm happy with RabbitMQ.
我无法对 node.js 发表评论,因为我还没有机会使用它。我对 RabbitMQ 很满意。
re: socket.io (are we talking websockets?) -- if this is for the browser (as the post above suggests), you could potentially bridge that into RabbitMQ. i.e. RabbitMQ is that flexible.
回复:socket.io(我们是在说 websockets 吗?)——如果这是针对浏览器的(如上面的帖子所暗示的),你可能会将它桥接到 RabbitMQ 中。即RabbitMQ就是那么灵活。
回答by old_sound
RabbitMQ is used as way to pass messages across applications, not necessarily users in a browser. You could then implement a RabbitMQ client in node.js for example that pushes the received messages to a browser.
RabbitMQ 被用作跨应用程序传递消息的方式,不一定是浏览器中的用户。然后,您可以在 node.js 中实现一个 RabbitMQ 客户端,例如将接收到的消息推送到浏览器。
See http://www.rabbitmq.com/blog/2010/11/12/rabbitmq-nodejs-rabbitjs/for an example.
有关示例,请参见http://www.rabbitmq.com/blog/2010/11/12/rabbitmq-nodejs-rabbitjs/。

