add zmq
This commit is contained in:
parent
31405d08bc
commit
435cb07f63
21
zmq/consumer.py
Normal file
21
zmq/consumer.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from datetime import datetime
|
||||||
|
import zmq
|
||||||
|
|
||||||
|
|
||||||
|
DATETIMES=[]
|
||||||
|
|
||||||
|
|
||||||
|
context = zmq.Context()
|
||||||
|
socket = context.socket(zmq.SUB)
|
||||||
|
socket.connect("tcp://127.0.0.1:5559")
|
||||||
|
|
||||||
|
socket.setsockopt_string(zmq.SUBSCRIBE, "test")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
m = socket.recv_string()
|
||||||
|
DATETIMES.append(datetime.now())
|
||||||
|
except Exception:
|
||||||
|
socket.close()
|
||||||
|
print(DATETIMES)
|
17
zmq/publisher.py
Normal file
17
zmq/publisher.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import zmq
|
||||||
|
|
||||||
|
|
||||||
|
context = zmq.Context()
|
||||||
|
socket = context.socket(zmq.PUB)
|
||||||
|
socket.bind("tcp://127.0.0.1:5559")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
msg_body = "a" * m
|
||||||
|
socket.send_string(f"test {msg_body}")
|
||||||
|
except Exception:
|
||||||
|
socket.close()
|
Loading…
Reference in New Issue
Block a user