如何使用一个Node.JS服务器从许多不同的用户订阅许多NEST设备

编程入门 行业动态 更新时间:2024-10-22 08:26:27
本文介绍了如何使用一个Node.JS服务器从许多不同的用户订阅许多NEST设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试为希望能够为一个或多个Node.js服务器上的许多不同用户预订许多(也许是十万个)NEST设备的客户端的项目范围.想法是聚合来自许多客户端拥有的许多设备的变更事件. Node.js可以处理那么多同时进行的Firebase更改订阅吗?最好如何管理?

I am trying to scope a project for a client that wants to be able to subscribe to many (perhaps 10's of thousands) of NEST devices for many different users from one or more Node.js servers. The idea being to aggregate change events from many devices owned by many clients. Could Node.js handle that many simultaneous Firebase change subscriptions? How would that best be managed?

谢谢

推荐答案

此处的Firebase工程师,

Firebase engineer here,

此当前方法的问题在于,Nest当前仅允许一次要进行身份验证的单个令牌,并且由于Firebase客户端一旦对身份验证进行身份验证就缓存身份验证状态,因此,为了在所述服务器之一上的单个进程中执行此操作,您必须验证,执行操作,然后取消验证,并对效率不高的每个操作重复执行.侦听效率特别低下,因为这意味着您需要打开 n 套接字连接,并且必须以这种方式在它们之间进行切换,这在一定程度上破坏了首先使用Firebase的目的(能够保持Firebase的正常运行).连接打开并获得推送更新.

The problem with this current approach is that Nest currently only allows a single token to authenticate at a time, and since Firebase clients cache authentication state once authenticated, in order to do this in a single process on one of said servers, you would have to auth, perform the operation, then unauth, and repeat for every operation which isn't very efficient. Listens are particularly inefficient, since this means you need to open up n socket connections, and having to switch between them in this manner somewhat defeats the purpose of using Firebase in the first place (being able to hold the connection open and get pushed updates).

您可以通过以下几种方法解决此问题:

You can solve this in a few ways:

  • 切换到多进程和多服务器,其中每个进程都有一个打开的套接字和自己的身份验证令牌.使用我们的节点或 Java 客户端通常是此处的最佳选择.
  • 使用流REST API 可以在同一台服务器.
  • Switch to multi-process and multi-server where each process has an open socket and its own auth token. Using our Node or Java client is typically the best option here.
  • Use the streaming REST API to open up multiple connections on the same server.

希望这会有所帮助!

更多推荐

如何使用一个Node.JS服务器从许多不同的用户订阅许多NEST设备

本文发布于:2023-10-28 01:12:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535063.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   服务器   用户   设备   JS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!