在 google 云中创建批量主题和订阅者

Create bulk topics & subscribers in google cloud

我正在寻找使用脚本或程序创建批量主题和订阅者的程序。我让所有主题和订阅者都在脚本中创建命令。

如何执行脚本?

一般有3种方式与Google云平台交互。

  1. 网络 UI (http://console.cloud.google.com/)
  2. 直接使用API(https://cloud.google.com/pubsub/docs/apis)
  3. 使用 Cloud SDK 命令行工具,尤其是 gcloud (https://cloud.google.com/sdk/gcloud/)

网络UI一般不适合bulk/automated动作,但后两者效果不错。使用 API 取决于你喜欢的语言,所以我将给出一个使用 gcloudbash 的例子(假设你已经安装并配置了 gcloud):

$ head -n 2 topics.txt
topic-1
topic-2
$ while read topic; do gcloud pubsub topics create $topic; done < topics.txt

订阅有点棘手,因为 gcloud pubsub subscriptions create 需要一个 --topic 标志以及订阅名称的位置参数,但这个想法非常相似。