Last active
October 14, 2020 12:37
-
-
Save peter-mcconnell/cc51b2b03415199e848a33897f3547f4 to your computer and use it in GitHub Desktop.
zmq sender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
simple zmq publisher | |
""" | |
import argparse | |
import json | |
import zmq | |
def send(filepath, address): | |
""" | |
send contents from a file to a zmq address | |
""" | |
context = zmq.Context() | |
socket = context.socket(zmq.REQ) | |
print(f"connecting to {address}") | |
socket.connect(address) | |
with open(filepath, "r") as data: | |
# send | |
socket.send_json(data.read()) | |
# receive | |
recv = socket.recv_json() | |
print(socket.recv) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Send json to zmq") | |
parser.add_argument( | |
"--filepath", type=str, help="path to json file" | |
) | |
parser.add_argument( | |
"--address", | |
type=str, | |
help="address", | |
default="tcp://127.0.0.1:5555", | |
) | |
args = parser.parse_args() | |
print(args.filepath) | |
send(args.filepath, args.address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment