在 GCP 上哪里托管 pub sub 发布者?

Where to host pub sub publisher on GCP?

我想创建一个发布者,它可以流式传输包含特定主题标签的推文并将其发送到 pub/sub 主题。

推文随后将通过云数据流提取,然后加载到 Big Query 数据库中。

在接下来的 article 中,他们做了类似的事情,其中​​发布者托管在 Google Compute Engine 实例上的 docker 图像上。

任何人都可以推荐替代 Google 云资源,它可以更简单地托管发布者代码,避免需要创建 docker 文件等吗? 发布者需要不断 运行。会云 运行 例如是一个合适的选择?

我可以想到一些解决方法:

  1. 避免容器架构的一种快速方法是在循环中使用 on_data 方法,例如,通过使用类似 while(true) 的方法或启动流,如 Create your Python script and run the code in a Compute Engine in the background with nohup python -u myscript.py. Or follow the steps described in Script on GCE to capture tweets 使用 tweepy.Stream 开始流式传输。

  2. 您可能需要重新考虑 Dockerfile 选项,因为它的配置可能并不那么困难,请参阅 Tweets & pipelines where there is a script that read the data and publish to PubSub, you will see that 9 lines are used for the Docker file and it is deployed in App Engine using Cloud Build. Another implementation with a Docker file that requires more steps is twitter-for-bigquery,如果有帮助,您会看到更多具体步骤和更多配置。

  3. Cloud Functions 也是另一种选择,在本指南中 Serverless Twitter with Google Cloud 您可以查看设计部分以了解它是否适​​合您的用例。

  4. Airflow with Twitter Scraper 可能适合您,因为 Cloud Composer 是 Airflow 的托管服务,您可以快速创建 Airflow 环境。它使用 Twint 库,查看 link 中的技术部分了解更多详细信息。

  5. Stream Twitter Data into BigQuery with Cloud Dataprep 是一种搁置复杂配置的解决方法。在这种情况下,作业不会一直 运行,但可以在几分钟内安排到 运行。