This fixes issue #1 #2
@@ -1,6 +1,7 @@
|
|||||||
from google.cloud import pubsub_v1
|
from google.cloud import pubsub_v1
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
import os
|
import os
|
||||||
|
import asyncio
|
||||||
|
|
||||||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/Users/Karen/AppData/Roaming/gcloud/application_default_credentials.json"
|
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/Users/Karen/AppData/Roaming/gcloud/application_default_credentials.json"
|
||||||
project_id = "fp-20230425"
|
project_id = "fp-20230425"
|
||||||
@@ -45,9 +46,20 @@ publisher.publish(topic_path, data=message)
|
|||||||
print("Message published.")
|
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
|
# Pull the message from the subscription
|
||||||
response = subscriber.pull(subscription=subscription_path, max_messages=1)
|
response = subscriber.pull(subscription=subscription_path, max_messages=1)
|
||||||
for received_message in response.received_messages:
|
for received_message in response.received_messages:
|
||||||
print("Received message: {}".format(received_message.message.data))
|
print("Received message: {}".format(received_message.message.data))
|
||||||
# Acknowledge the message to mark it as processed
|
# Acknowledge the message to mark it as processed
|
||||||
subscriber.acknowledge(subscription_path, [received_message.ack_id])
|
subscriber.acknowledge(subscription_path, [received_message.ack_id])
|
||||||
|
'''
|
||||||
Reference in New Issue
Block a user