在 Cloud Functions for Firebase 上运行 Web 套接字? [英] Run a web socket on Cloud Functions for Firebase?

查看:25
本文介绍了在 Cloud Functions for Firebase 上运行 Web 套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我实际上有一个使用 http 请求在 Cloud Functions for Firebase 上运行的 REST api,但现在我需要将实时请求的数据同步到函数.我读过一些关于网络套接字的东西.

Hello I actually have a REST api running on Cloud Functions for Firebase using http request, but now I need to sync the data on real time requesting to the functions. I read something about web sockets.

有没有办法在 Cloud Functions for Firebase 上运行 Web 套接字?

Is there a way to run a web socket on Cloud Functions for Firebase?

推荐答案

这不适合 Cloud Functions.随着时间的推移,Websocket 依赖于与同一服务器的长期连接;Cloud Functions 是临时计算实例,在没有流量时会停止运行.无法强制或保证 Cloud Function 将继续运行或无限期保持连接打开.

This is not going to be a good fit for Cloud Functions. Websockets rely on long-lived connections to the same server over time; Cloud Functions are ephemeral compute instances that are spun down when there's no traffic. There's no way to force or guarantee that a Cloud Function will keep running or hold a connection open indefinitely.

我建议您在此处使用 Firebase 实时数据库作为管道进行调查,而不是尝试将实时添加到 Cloud Functions.

I would encourage you to investigate using the Firebase Realtime Database as a conduit here instead of trying to add realtime to Cloud Functions.

这篇关于在 Cloud Functions for Firebase 上运行 Web 套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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