File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ redis
2+ protobuf
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments