我正在开发实时实时网络应用程序。
浏览器用户应该能够通过 node.js 服务器相互通信。一个用户写了一条消息,所有其他用户都会收到它。
我不太明白 RabbitMQ 是如何工作的。但从快速阅读看来,它处理消息的发布/订阅。
用户(在浏览器中)发布某些内容,而订阅者(在其他浏览器中)收到该消息。这不就是 Socket.io 对 websocket 所做的吗?
这是我的问题:
- 它们各自的优点/缺点是什么?
- Socket.io 能否替代 RabbitMQ?
- 是否存在我需要 RabbitMQ 用于 Socket.io 无法满足的 Web 应用程序的场景?
最佳答案
更新
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.
如果您只有这些简单的要求,那么仅使用 socket.io 就足够了。。您只需要留言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 makes the queue a First-In-First-Out (FIFO) data structure.
这是我认为队列的一个重要属性。先进先出属性虽然使用像 beanstalkd 这样的高级消息队列,但您可以为作业指定优先级。
我希望这有任何意义;)
I'm doing real time live web app development.
您能否解释得更好一点,以便我们给您更好的答案?
I don't quite get how RabbitMQ works. But from quick reading it seems that it handles publication/subscription of messages.
请参阅下面有关消息队列的报价。让它沉入一段时间。您还可以阅读有关 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),这是因为大多数浏览器不支持 websockets。但例如 Google Chrome 确实已经支持 websockets。我相信 websockets 是 future 的传输(但还不是!)。当您查看 Socket.io's browser support page您会注意到 Socket.io 确实支持所有主流浏览器(有些甚至是古老的)。好消息是它围绕一个很好的 API 进行了包装。
What are the advantages/disadvantages for each one of them?
您将苹果与橙子进行比较,所以比较有点奇怪。
RabbitMQ
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.
优势
- 这是一个很好的消息队列。我个人会使用 redis或 beanstalkd .
缺点:
- 并不是真正的“浏览器”。
Socket.io
Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms.
优势
- 用于浏览器
缺点
- 它不是消息队列。
Can Socket.io replace RabbitMQ?
不,你不能,因为它们是两个完全不同的东西。您正在将苹果与橙子进行比较。您应该尝试从我引用的网站中理解这两种描述。
关于node.js - RabbitMQ vs Socket.io?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6636213/