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