diff --git a/examples/query_topic_message.py b/examples/query_topic_message.py index 9dc81f1..b5078b9 100644 --- a/examples/query_topic_message.py +++ b/examples/query_topic_message.py @@ -14,17 +14,20 @@ def query_topic_messages(): client = Client(network) def on_message_handler(topic_message): - print("Received topic message:", topic_message) + print(f"Received topic message: {topic_message}") def on_error_handler(e): - print("Subscription error:", e) + print(f"Subscription error: {e}") + if "Stream removed" in str(e): + print("Reconnecting due to stream removal...") + query_topic_messages() query = ( TopicMessageQuery() - .set_topic_id("0.0.5337028") + .set_topic_id("0.0.5337028") .set_start_time(datetime.utcnow()) .set_chunking_enabled(True) - .set_limit(5) + .set_limit(0) ) query.subscribe( @@ -33,8 +36,9 @@ def on_error_handler(e): on_error=on_error_handler ) - time.sleep(10) - print("Done waiting. Exiting.") + print("Subscription started. Waiting for messages...") + while True: + time.sleep(10) if __name__ == "__main__": query_topic_messages() diff --git a/examples/topic_message_submit.py b/examples/topic_message_submit.py index 89a4a1d..b0cf4af 100644 --- a/examples/topic_message_submit.py +++ b/examples/topic_message_submit.py @@ -17,7 +17,7 @@ def submit_message(message): operator_id = AccountId.from_string(os.getenv('OPERATOR_ID')) operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY')) - topic_id = TopicId.from_string(os.getenv('TOPIC_ID')) + topic_id = TopicId.from_string("0.0.5337028") client.set_operator(operator_id, operator_key) @@ -35,4 +35,4 @@ def submit_message(message): sys.exit(1) if __name__ == "__main__": - submit_message("Hello, Hedera!") \ No newline at end of file + submit_message("four") \ No newline at end of file