20 lines
631 B
Python
20 lines
631 B
Python
import json
|
|
import logging
|
|
|
|
logger = logging.getLogger("communication")
|
|
|
|
def getTopic(hugvey_id):
|
|
return "hv{}".format(hugvey_id)
|
|
|
|
|
|
def zmqSend(socket, hugvey_id, msg):
|
|
msgData = json.dumps(msg)
|
|
topic = getTopic(hugvey_id)
|
|
logger.info("Send 0mq to {} containing {}".format(topic, msg))
|
|
socket.send_multipart([topic.encode(), msgData.encode()])
|
|
|
|
async def zmqReceive(socket):
|
|
topic, msg = await socket.recv_multipart()
|
|
hugvey_id = topic.decode()[2:]
|
|
logger.info("Received 0mq messages for Hugvey #{} containing {}".format(hugvey_id, msg.decode()))
|
|
return int(hugvey_id), json.loads(msg.decode())
|