Wrapped the publish call to catch DeadlineExceeded exceptions
This commit is contained in:
@@ -41,7 +41,7 @@ subscription = subscriber.create_subscription(
|
|||||||
# Publish a message to the topic
|
# Publish a message to the topic
|
||||||
# Read the data from the csv file
|
# 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 = "C:/Users/Karen/Desktop/zipcodes.csv"
|
file_path = "zipcodes.csv"
|
||||||
|
|
||||||
with open(file_path, "r") as csv_file:
|
with open(file_path, "r") as csv_file:
|
||||||
reader = csv.reader(csv_file)
|
reader = csv.reader(csv_file)
|
||||||
@@ -49,7 +49,10 @@ with open(file_path, "r") as csv_file:
|
|||||||
for row in reader:
|
for row in reader:
|
||||||
# Format the data as a string and publish it to the topic
|
# Format the data as a string and publish it to the topic
|
||||||
data = ",".join(row).encode("utf-8")
|
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()}")
|
print(f"Published message ID {future.result()}")
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user