Run a web socket on Cloud Functions for Firebase?

前端 未结 2 814
别那么骄傲
别那么骄傲 2020-12-03 21:09

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

相关标签:
2条回答
  • 2020-12-03 21:54

    Theoretically you could use two different layers: one to manage the websocket connections and another layer to handle the data processing.

    The websocket layer will not be Cloud Functions, but a Docker container running Push Pin in Cloud Run and that’ll route HTTP calls to your Cloud Functions to do the actual data processing.

    0 讨论(0)
  • 2020-12-03 22:07

    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.

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

    0 讨论(0)
提交回复
热议问题