From 435cb07f636057f6ff93625923737ee258d3b1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 12:16:11 +0200 Subject: [PATCH] add zmq --- zmq/consumer.py | 21 +++++++++++++++++++++ zmq/publisher.py | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 zmq/consumer.py create mode 100644 zmq/publisher.py diff --git a/zmq/consumer.py b/zmq/consumer.py new file mode 100644 index 0000000..e0be251 --- /dev/null +++ b/zmq/consumer.py @@ -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) \ No newline at end of file diff --git a/zmq/publisher.py b/zmq/publisher.py new file mode 100644 index 0000000..970531d --- /dev/null +++ b/zmq/publisher.py @@ -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() \ No newline at end of file