Skip to content

Commit af553ec

Browse files
add subscriber debug script
1 parent 9e77304 commit af553ec

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
redis
2+
protobuf
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
import redis
3+
4+
try:
5+
import helix_pb2 as hx
6+
except ImportError:
7+
sys.stderr.write("Error: Missing generated Python code. Please compile 'helix.proto' using 'protoc' before running this script.\n")
8+
sys.exit(1)
9+
10+
11+
CHANNELS: list[str] = ["hal", "application1", "application2"]
12+
13+
14+
def main() -> None:
15+
client: redis.Redis = redis.Redis(host='localhost', port=6379, db=0)
16+
pubsub: redis.client.PubSub = client.pubsub()
17+
18+
for channel in CHANNELS:
19+
pubsub.subscribe(channel)
20+
print(f"Subscribed to '{channel}'")
21+
print()
22+
23+
for msg in pubsub.listen():
24+
if msg.get("type") != "message":
25+
continue
26+
27+
message: hx.Message = hx.Message()
28+
message.ParseFromString(msg.get("data"))
29+
print(f"{message}")
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)