Wrapped the publish call to catch DeadlineExceeded exceptions

This commit is contained in:
cheezedoodle2
2023-05-18 14:45:18 -07:00
parent 24a1f04a2f
commit b8a4875e9d
+5 -2
View File
@@ -41,7 +41,7 @@ subscription = subscriber.create_subscription(
# Publish a message to the topic
# Read the data from the csv file
# file_path = "C:/Users/Karen/Desktop/zipcodes.csv"
file_path = "C:/Users/Karen/Desktop/zipcodes.csv"
file_path = "zipcodes.csv"
with open(file_path, "r") as csv_file:
reader = csv.reader(csv_file)
@@ -49,7 +49,10 @@ with open(file_path, "r") as csv_file:
for row in reader:
# Format the data as a string and publish it to the topic
data = ",".join(row).encode("utf-8")
future = publisher.publish(topic_path, data)
try:
future = publisher.publish(topic_path, data)
except DeadlineExceeded as de:
print(f"Caught DeadlineExceeded exception: {de}")
print(f"Published message ID {future.result()}")
'''