我刚刚更新到google-cloud-pubsub版本0.28,其中Google将Python客户端重组为PublisherClient和SubscriberClient。我试图连接到localhost上的Pubsub模拟器,但是尽管设置了环境变量,它仍然连接到cloud pubsub服务,它可以列出来自cloud pubsub的所有主题,但不能列出来自模拟器的主题。
以下是我用来连接模拟器的代码
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)
以下是例外:
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 :(得分:0)
该问题已在0.29版本中修复