简体   繁体   English

如何通过Google-cloud-pubsub 0.28版的PublisherClient使用Pubsub仿真器

[英]How to use Pubsub Emulator with PublisherClient from google-cloud-pubsub version 0.28

I just update to google-cloud-pubsub version 0.28, where Google restructured the Python client into a PublisherClient and SubscriberClient. 我只是更新到google-cloud-pubsub 0.28版,在该版本中Google将Python客户端重组为PublisherClient和SubscriberClient。 I was trying to connect to the Pubsub Emulator on localhost, but despite setting the environment variables, it still connects to the cloud pubsub service, where it can list all the topic from cloud pubsub, but not the ones from emulator. 我试图连接到本地主机上的Pubsub仿真器,但是尽管设置了环境变量,但它仍连接到云pubsub服务,该服务可以列出来自云pubsub的所有主题,但不能列出来自仿真器的主题。

Here is the code I used to connect to emulator 这是我用来连接模拟器的代码

from google.cloud import pubsub
import os
os.environ['PUBSUB_EMULATOR_HOST'] = 'localhost:8085'
os.environ['GOOGLE_CLOUD_PROJECT'] = 'my-project'
publisher = pubsub.PublisherClient()
topic = 'projects/my-project/topics/abc'
publisher.get_topic(topic)

and here is the exception: 这是一个例外:

Traceback (most recent call last):
  File "<input>", line 5, in <module>
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/cloud/pubsub_v1/_gapic.py", line 42, in <lambda>
    fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw)
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/cloud/gapic/pubsub/v1/publisher_client.py", line 341, in get_topic
    return self._get_topic(request, options)
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/gax/api_callable.py", line 452, in inner
    return api_caller(api_call, this_settings, request)
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/gax/api_callable.py", line 438, in base_caller
    return api_call(*args)
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/gax/api_callable.py", line 376, in inner
    return a_func(*args, **kwargs)
  File "/Users/sx5640/Envs/uie/lib/python2.7/site-packages/google/gax/retry.py", line 127, in inner
    ' classified as transient', exception)
RetryError: RetryError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.NOT_FOUND, Resource not found (resource=abc).)>)

此问题已在0.29版中修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM