Google Cloud Pub/Sub 到 BigQuery 模板主题订阅

Google Cloud Pub/Sub to BigQuery template topic subscription

在为 BigQuery 模板创建新数据流 Pub/Sub 时,可以指定 PubSub topic。似乎无法提供现有的 PubSub subscription,而是 Dataflow 模板在每次运行时创建一个新订阅。

据我了解 PubSub 模型,确保我们继续从主题中的同一位置读取数据的唯一方法是重用相同的订阅,这里似乎没有这样的选项。

当用户想要重新部署这样一个数据流模板时会发生什么?我们会丢失部署之间的所有数据吗?

没错,google 提供的 Pub/Sub 到 BigQuery 模板不支持将订阅作为参数传递('s an older answer by a googler confirming this). However, it should be easy to edit it so that it does so. You would only need to replace getInputTopicgetSubscription 等效。反过来,这应该传递给 PubsubIO.readMessagesWithAttributes().fromSubscription (options.getSubscription()) 方法(参见 here) instead of fromTopic. After creating your new pipeline, you'd need to create and stage your template.

作为一项更新,现在有一个针对此用例的新模板。

https://cloud.google.com/dataflow/docs/guides/templates/provided-streaming#pubsub-subscription-to-bigquery

gcloud dataflow jobs run $jobname \
  --project=$project \
  --disable-public-ips \
  --gcs-location gs://dataflow-templates-$location/latest/PubSub_Subscription_to_BigQuery \
  --worker-machine-type n1-standard-1 \
  --region $location \
  --staging-location gs://$bucket/pss-to-bq \
  --parameters inputSubscription=projects/$project/subscriptions/$subscription,outputTableSpec=$dataset.$table