最新的 python 演示可以工作,但需要 ruby API viewer 权限
Google 视频系列#pubsubmadeeasy 第 3 集中展示的 Python 演示
Cloud Pub/Sub in Action 使用视频指示您添加的权限,特别是使用更新的代码(请参阅下面的注释)正常工作
Pub/Sub Publisher
Pub/Sub Subscriber
但切换到ruby API 需要将查看者权限添加到演示中创建的服务帐户。注意:使用红宝石3.1.0 和gem 'google-cloud-pubsub', '~> 2.9', '>= 2.9.1'。
Pub/Sub Viewer
python 示例设置注意事项:
- 使用 python 3.10.1
- 示例代码
https://github.com/googleapis/python-pubsub.git
具体来说
https://github.com/googleapis/python-pubsub/tree/main/samples/snippets/quickstart
virtualenv venv && source venv/bin/activate
pip install --upgrade google-cloud-pubsub
export GOOGLE_APPLICATION_CREDENTIALS=downloaded_key.json
export PROJECT=`gcloud config get-value project`
错误示例:
订阅错误
/home/dever/.gem/ruby/3.1.0/gems/google-cloud-pubsub-v1-0.6.2/lib/google/cloud/pubsub/v1/subscriber/client.rb:499:
in `rescue in get_subscription':
7:User not authorized to perform this action.. debug_error_string:
{"created":"@1642638738.357361477",
"description":"Error received from peer ipv6:[2607:f8b0:4006:80a::200a]:443",
"file":"src/core/lib/surface/call.cc","file_line":1063,
"grpc_message":"User not authorized to perform this action.","grpc_status":7}
(Google::Cloud::PermissionDeniedError)
发布错误
/home/dever/.gem/ruby/3.1.0/gems/google-cloud-pubsub-v1-0.6.2/lib/google/cloud/pubsub/v1/publisher/client.rb:574:
in `rescue in get_topic':
7:User not authorized to perform this action..
debug_error_string:{"created":"@1642638676.763569110",
"description":"Error received from peer ipv6:[2607:f8b0:4006:80a::200a]:443",
"file":"src/core/lib/surface/call.cc","file_line":1063,
"grpc_message":"User not authorized to perform this action.","grpc_status":7}
(Google::Cloud::PermissionDeniedError)