mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-10-05 05:53:36 +00:00
22 lines
804 B
Python
22 lines
804 B
Python
|
import zmq
|
||
|
from zmq.eventloop import ioloop
|
||
|
from zmq.eventloop.zmqstream import ZMQStream
|
||
|
|
||
|
from config import PUBLISHER_PORT, RECEIVER_PORT
|
||
|
|
||
|
ioloop.install()
|
||
|
|
||
|
|
||
|
class ComponentBase:
|
||
|
def __init__(self, anchor, event_handler, zmq_context=None):
|
||
|
self.anchor = anchor
|
||
|
self.event_handler = event_handler
|
||
|
self.zmq_context = zmq_context or zmq.Context.instance()
|
||
|
self.zmq_sub_socket = self.zmq_context.socket(zmq.SUB)
|
||
|
self.zmq_sub_socket.setsockopt_string(zmq.SUBSCRIBE, anchor)
|
||
|
self.zmq_sub_socket.connect('tcp://localhost:{}'.format(PUBLISHER_PORT))
|
||
|
self.zmq_sub_stream = ZMQStream(self.zmq_sub_socket)
|
||
|
self.zmq_push_socket = self.zmq_context.socket(zmq.PUSH)
|
||
|
self.zmq_push_socket.connect('tcp://localhost:{}'.format(RECEIVER_PORT))
|
||
|
|