def main (): # Start child threads ctx = zmq.Context.instance() p_thread = Thread(target=publisher_thread) s_thread = Thread(target=subscriber_thread) p_thread.start() s_thread.start() pipe = zpipe(ctx) subscriber = ctx.socket(zmq.XSUB) subscriber.connect("tcp://localhost:6000") publisher = ctx.socket(zmq.XPUB) publisher.bind("tcp://*:6001") l_thread = Thread(target=listener_thread, args=(pipe[1],)) l_thread.start() try: monitored_queue(subscriber, publisher, pipe[0], 'pub', 'sub') except KeyboardInterrupt: print ("Interrupted") del subscriber, publisher, pipe ctx.term()
def main(): # Start child threads ctx = zmq.Context.instance() p_thread = Thread(target=publisher_thread) s_thread = Thread(target=subscriber_thread, args=(['A', 'B'], 20)) s_thread2 = Thread(target=subscriber_thread, args=(['A', 'C'], 20, 2)) p_thread.start() s_thread.start() s_thread2.start() # pipe = zpipe(ctx) subscriber = ctx.socket(zmq.XSUB) subscriber.connect("tcp://localhost:6000") publisher = ctx.socket(zmq.XPUB) publisher.bind("tcp://*:6001") # l_thread = Thread(target=listener_thread, args=(pipe[1],)) l_thread = Thread(target=listener_thread) l_thread.start() listener = ctx.socket(zmq.PAIR) listener.connect('inproc://listener') try: monitored_queue(subscriber, publisher, listener, b'pub', b'sub') # monitored_queue(subscriber, publisher, pipe[0], b'pub', b'sub') except KeyboardInterrupt: print("Interrupted") del subscriber, publisher, pipe ctx.term()
def main (): # Start child threads ctx = zmq.Context.instance() p_thread = Thread(target=publisher_thread) s_thread = Thread(target=subscriber_thread) p_thread.start() s_thread.start() pipe = zpipe(ctx) subscriber = ctx.socket(zmq.XSUB) subscriber.connect("tcp://localhost:6000") publisher = ctx.socket(zmq.XPUB) publisher.bind("tcp://*:6001") l_thread = Thread(target=listener_thread, args=(pipe[1],)) l_thread.start() try: monitored_queue(subscriber, publisher, pipe[0], 'pub', 'sub') except KeyboardInterrupt: print ("Interrupted") del subscriber, publisher, pipe ctx.term()
def startBroker(self): # Start child threads ctx = zmq.Context.instance() pipe = self.zpipe(ctx) print ("Broker binding to subscriber port " + self._subscriberPort) subscriber = ctx.socket(zmq.XSUB) subscriber.bind("tcp://*:" + self._subscriberPort) print ("Broker binding to publisher port " + self._publisherPort) publisher = ctx.socket(zmq.XPUB) publisher.bind("tcp://*:" + self._publisherPort) l_thread = Thread(target=self.listener_thread, args=(pipe[1],)) l_thread.start() print("Broker online...") try: monitored_queue(subscriber, publisher, pipe[0], 'pub', 'sub') except KeyboardInterrupt: print ("Interrupted") del subscriber, publisher, pipe ctx.term()