实时应用新手 - Node.JS + Redis 或 RabbitMQ ->客户端/服务器如何? [英] Real-time application newbie - Node.JS + Redis or RabbitMQ -> client/server how?

查看:36
本文介绍了实时应用新手 - Node.JS + Redis 或 RabbitMQ ->客户端/服务器如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是实时应用程序开发的新手,我正在努力解决无数的选择.我已经阅读了尽可能多的博客文章、笔记和论文,人们很乐意分享.然而,在我的小脑袋里,一个简单的问题似乎没有答案.我认为其他一些人可能也有同样的问题,所以我不妨注册并在 SO 上发帖.如下:

I am a newbie to real-time application development and am trying to wrap my head around the myriad options out there. I have read as many blog posts, notes and essays out there that people have been kind enough to share. Yet, a simple problem seems unanswered in my tiny brain. I thought a number of other people might have the same issues, so I might as well sign up and post here on SO. Here goes:

我正在构建一个小型实时应用程序,它是异步聊天 + 另一个有趣的功能.我将我的选择归结为以下两个选项:

I am building a tiny real-time app which is asynchronous chat + another fun feature. I boiled my choices down to the following two options:

  1. LAMP + RabbitMQ
  2. Node.JS + Redis + Pub-Sub

我相信我已经掌握了开始学习和构建它的基础知识.但是,我的(严重 n00b)问题是:

I believe that I get the basics to start learning and building this out. However, my (seriously n00b) questions are:

  • 我如何与最终用户进行通信 -> 客户端与服务器之间的通信?那会是简单的 Javascript 长/无限轮询吗?
  • 在这两者中,从单个 Slice(假设有 100 到 1,000 个用户)构建和管理哪个可能更有效?
  • 我是否应该在老派"范式中使用 jQuery 构建所有内容,然后确定哪个堆栈可能更有意义?只是为了让我可以将产品充实为原型,然后优化"它.还是一个一个地编写不仅仅是优化?(我觉得是这样,但我个人不是 100% 的)

我希望这不是一个疯狂的问题,也不会马上被激怒.希望得到一些建设性的反馈,爱这个社区!

I hope this isn't a crazy question and won't get flamed right away. Would love some constructive feedback, love this community!

谢谢.

推荐答案

从架构上讲,这两种选择都与将数据存储在 Oracle 数据库服务器中供另一个应用程序检索一样.

Architecturally, both of your choices are the same as storing data in an Oracle database server for another application to retrieve.

RabbitMQ 和 Redis 解决方案都要求您的应用连接到处理数据通信的中间服务器.Redis 最像 Oracle,因为它可以简单地用作具有网络 API 的持久性数据库.但 RabbitMQ 有点不同,因为 MQ Broker 并不真正负责持久化数据.如果您在发布消息时正确配置并使用正确的选项,那么 RabbitMQ 实际上会为您保留数据,但您无法将数据取出,除非作为正常消息队列过程的一部分.换句话说,RabbitMQ 用于传递消息,仅提供持久性作为从网络问题或系统崩溃中恢复的一种方式.

Both the RabbitMQ and the Redis solution require your apps to connect to an intermediary server that handles the data communications. Redis is most like Oracle, because it can be used simply as a persistent database with a network API. But RabbitMQ is a little different because the MQ Broker is not really responsible for persisting data. If you configure it right and use the right options when publishing a message, then RabbitMQ will actually persist the data for you but you can't get the data out except as part of the normal message queueing process. In other words, RabbitMQ is for communicating messages and only offers persistence as a way of recovering from network problems or system crashes.

我建议使用 RabbitMQ 和您已经熟悉的任何编程语言.由于 LAMP 中的 M 通常被解释为 MySQL,这意味着您要么根本不使用 MySQL,要么只将其用于数据的长期存储,而不是用于实时通信.

I would suggest using RabbitMQ and whatever programming languages you are already familiar with. Since the M in LAMP is usually interpreted as MySQL, this means that you would either not use MySQL at all, or only use it for long term storage of data, not for the realtime communications.

RabbitMQ 站点有大量关于使用 AMQP 构建应用程序的文档.我建议在安装 RabbitMQ 之后,通读 rabbitmqctl 的文档,然后创建一个 vhost 进行实验.这样,无需重置即可轻松清理实验一切.我还建议仅使用主题交换,因为您可以通过在 routing_key 中使用通配符来模拟直接和扇出交换的行为.请记住,您只向交换器发布消息,并且只接收来自队列的消息.交换器负责将消息的 routing_key 与队列的 binding_key 进行模式匹配,以确定哪些队列应该接收消息的副本.即使您只打算将消息发送到与 routing_key 同名的一个队列,也值得学习整个 AMQP 模型.

The RabbitMQ site has a huge amount of documentation about building apps with AMQP. I suggest that after you install RabbitMQ, you read through the docs for rabbitmqctl and then create a vhost to experiment in. That way it is easy to clean up your experiments without resetting everything. I also suggest using only topic exchanges because you can emulate the behavior of direct and fanout exchanges by using wildcards in the routing_key. Remember, you only publish messages to exchanges, and you only receive messages from queues. The exchange is responsible for pattern matching the message's routing_key to the queue's binding_key to determine which queues should receive a copy of the message. It is worthwhile learning the whole AMQP model even if you only plan to send messages to one queue with the same name as the routing_key.

如果您在浏览器中构建客户端,并且想要构建原型,那么您现在应该考虑只使用 XHR,然后转向 Kamaloka-js 之类的东西,它是 AMQP 的纯 Javascript 实现(AMQ协议),这是用于与 RabbitMQ 消息代理通信的标准协议.换句话说,用你今天所知道的来构建它,然后在你的工具箱中有长期未来的东西 (AMQP) 来加速它.

If you are building your client in the browser, and you want to build a prototype, then you should consider just using XHR today, and then move to something like Kamaloka-js which is a pure Javascript implementation of AMQP (the AMQ Protocol) which is the standard protocol used to communicate to a RabbitMQ message broker. In other words, build it with what you know today, and then speed it up later which something (AMQP) that has a long term future in your toolbox.

这篇关于实时应用新手 - Node.JS + Redis 或 RabbitMQ ->客户端/服务器如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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