下面的代码订阅一个主题,几个月前就开始工作了。
from google.cloud import pubsub
def callback(message):
print(message.data)
message.ack()
project_id = "my_project"
topic_name = "xxx"
subscription_name = "xxx"
subscriber = pubsub.SubscriberClient()
topic = "projects/{}/topics/{}".format(project_id, topic_name)
subscription_name = 'projects/{}/subscriptions/{}'.format(project_id, subscription_name)
subscription = subscriber.subscribe(subscription_name)
future = subscription.open(callback)
try:
future.result()
except Exception as ex:
subscription.close()
raise
我现在尝试运行它,但收到以下错误消息:
<模块>中的文件“pubsub_sub.py”第16行
订阅=订阅者.订阅(订阅名称)
类型错误:订阅()至少需要3个参数(给定2个)
正如Google-Cloud Pub/Sub文档中所述,看来我的代码是正确的。此外,正如我所说,同样的代码在过去也有效。有什么建议吗?