forked from SVIG/python-bootcamp
modified fp1
This commit is contained in:
@@ -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])
|
||||
'''
|
||||
Reference in New Issue
Block a user