Skip to content

Commit

Permalink
message stream working - 2025 here we go
Browse files Browse the repository at this point in the history
  • Loading branch information
nadineloepfe committed Jan 2, 2025
1 parent ba404d1 commit 475d063
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions examples/query_topic_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
4 changes: 2 additions & 2 deletions examples/topic_message_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -35,4 +35,4 @@ def submit_message(message):
sys.exit(1)

if __name__ == "__main__":
submit_message("Hello, Hedera!")
submit_message("four")

0 comments on commit 475d063

Please sign in to comment.