From f64334f24de70103c6122cce735c6d087b4638eb Mon Sep 17 00:00:00 2001 From: Elena Kolevska Date: Mon, 23 Sep 2024 02:01:15 +0100 Subject: [PATCH] more readable example Signed-off-by: Elena Kolevska --- examples/pubsub-streaming/subscriber.py | 33 +++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/pubsub-streaming/subscriber.py b/examples/pubsub-streaming/subscriber.py index f6f9078a..701f5775 100644 --- a/examples/pubsub-streaming/subscriber.py +++ b/examples/pubsub-streaming/subscriber.py @@ -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()