我创建了一个应用程序,用于在GOOGLE中发布关于某个主题的特定数据 云 用于发布数据的Google文档中提供的代码 (https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/read-write-to-cloud-storage)。
它工作正常。现在我想订阅这个TOPIC。我做的是
打开一个新终端(Linux mint)
然后我按照以下步骤进行操作
$ virtualenv env
$ source env / bin / activate
$ pip install -r requirements.txt(安装Appopriate Libraries)
4.然后我运行我的Subscriber.py文件
def create_subscription(project,topic_name,subscription_name):
subscriber = pubsub_v1.SubscriberClient()
topic_path = subscriber.topic_path(project, topic_name)
subscription_path = subscriber.subscription_path(project,
subscription_name)
subscription = subscriber.create_subscription(
subscription_path, topic_path)
print('Subscription created: {}'.format(subscription))
def receive_messages(project, subscription_name):
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_name)
def callback(message):
print('Received message: {}'.format(message))
message.ack()
subscriber.subscribe(subscription_path, callback=callback)
print('Listening for messages on
{}'.format(subscription_path))
while True:
time.sleep(60)
//calling above methods using appropriate parameters
create_subscription("test-1-180006","TOPIC","SUB1")
receive_messages("test-1-180006","SUB1")
但是当我运行上面的代码时它工作正常但没有显示任何内容。只显示以下消息
Listening for messages on projects/test-1-180006/subscriptions/SUB1