Skip to content

Commit

Permalink
more readable example
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <elena@kolevska.com>
  • Loading branch information
elena-kolevska committed Sep 23, 2024
1 parent daad173 commit f64334f
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions examples/pubsub-streaming/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@ def main():

try:
for i in range(5):
try:
message = subscription.next_message()
if message is None:
print('No message received within timeout period.')
continue

# Process the message
response_status = process_message(message)

if response_status == 'success':
subscription.respond_success(message)
elif response_status == 'retry':
subscription.respond_retry(message)
elif response_status == 'drop':
subscription.respond_drop(message)

except Exception as e:
print(f'Error getting message: {e}')
break
message = subscription.next_message()
if message is None:
print('No message received within timeout period.')
continue

# Process the message
response_status = process_message(message)

if response_status == 'success':
subscription.respond_success(message)
elif response_status == 'retry':
subscription.respond_retry(message)
elif response_status == 'drop':
subscription.respond_drop(message)

finally:
subscription.close()
Expand Down

0 comments on commit f64334f

Please sign in to comment.