Add ability to message another component to ComponentBase

This commit is contained in:
Bálint Bokros 2017-11-27 18:20:54 +01:00
parent 66d684f022
commit 1d5abaaea0

View File

@ -1,3 +1,4 @@
import json
import zmq
from zmq.eventloop import ioloop
from zmq.eventloop.zmqstream import ZMQStream
@ -19,3 +20,12 @@ class ComponentBase:
self.zmq_push_socket = self.zmq_context.socket(zmq.PUSH)
self.zmq_push_socket.connect('tcp://localhost:{}'.format(RECEIVER_PORT))
def message_other(self, anchor, data):
encoded_anchor = anchor.encode('utf-8')
message = {
'anchor': anchor,
'data': data
}
encoded_message = json.dumps(message).encode('utf-8')
self.zmq_push_socket.send_multipart([encoded_anchor, encoded_message])