From d72087ac9f24ea18602148b9f99c4be4221f1bc1 Mon Sep 17 00:00:00 2001 From: Karen Zeng Date: Thu, 27 Apr 2023 19:17:28 -0400 Subject: [PATCH] modified fp1 --- fp1.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fp1.py b/fp1.py index 7c34e0c..0426645 100644 --- a/fp1.py +++ b/fp1.py @@ -1,6 +1,7 @@ from google.cloud import pubsub_v1 from google.oauth2 import service_account import os +import asyncio os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/Users/Karen/AppData/Roaming/gcloud/application_default_credentials.json" project_id = "fp-20230425" @@ -45,9 +46,20 @@ publisher.publish(topic_path, data=message) print("Message published.") +async def receive_messages(): + response = subscriber.pull(subscription=subscription_path, max_messages=1) + for received_message in response.received_messages: + print("Received message: {}".format(received_message.message.data)) + + +asyncio.run(receive_messages()) + + +''' # Pull the message from the subscription response = subscriber.pull(subscription=subscription_path, max_messages=1) for received_message in response.received_messages: print("Received message: {}".format(received_message.message.data)) # Acknowledge the message to mark it as processed subscriber.acknowledge(subscription_path, [received_message.ack_id]) +''' \ No newline at end of file