【问题标题】:How can I have a continuous firebase cloud function for a continuous stream of data?如何为连续的数据流提供连续的 Firebase 云功能?
【发布时间】:2019-04-19 11:07:31
【问题描述】:

我需要使用 Twitter Stream API 将推文数据流式传输到我的 firebase 云函数,如下所示:

client.stream('statuses/filter', params,  stream => {

  stream.on('data', tweet => {
    console.log(tweet);
  })

  stream.on('error', error => {
    console.log(error)
  })

})

流是连续的,但 Firebase 云功能会在一段时间后关闭。我可以使用什么解决方案来持续接收流数据?

【问题讨论】:

    标签: firebase twitter google-cloud-functions twitter-streaming-api


    【解决方案1】:

    Cloud Functions 的最长运行时间为 540 秒 as documented。您可能不得不考虑使用Compute Engine Instance from Google Cloud,您可以在其中无限制地运行代码。或者您可以考虑使用Google Cloud Scheduler 每隔 x 次运行一次您的函数以获取新推文。

    【讨论】:

    • 谢谢,这很有帮助。我想我要么使用 Compute Engine 实例,要么使用 Heroku 等其他平台来运行后端。
    【解决方案2】:

    接受的回复建议运行 GCE,虽然它肯定是正确的,但我想指出,任何对 Cloud Functions(无服务器解决方案)感兴趣的人都可能会发现 GAE(App Engine)对于流数据更可行。

    我们的应用程序使用 App Engine Standard 作为提取服务,它的工作原理就像一个魅力 - 消除了 GCE 所需的开销。如果您的应用需要高级网络功能,App Engine Flexible 或 GKE (Kubernetes Engine) 也可能需要考虑!

    【讨论】:

      猜你喜欢
      • 2016-03-21
      • 2021-04-04
      • 2018-10-19
      • 2018-04-13
      • 2019-03-04
      • 2017-10-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多