How to use the zmq.PUB function in zmq

To help you get started, we’ve selected a few zmq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benoitc / uzmq / tests / test_zmq.py View on Github external
def test_pubsub(self):
        pub, sub = self.create_bound_pair(zmq.PUB, zmq.SUB)
        sub.setsockopt(zmq.SUBSCRIBE,b'')
        wait()

        loop = pyuv.Loop.default_loop()
        s = ZMQ(loop, sub)
        s1 = ZMQ(loop, pub)

        r = []
        def cb(stream, msg, err):
            r.append(msg[0])
            s.stop()
            s1.stop()

        s.start_read(cb)
        s1.write(b"message")
github BBN-Q / Auspex / test / matplot-server.py View on Github external
import zmq
from random import randrange
import time
import numpy as np

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5556")

context2 = zmq.Context()
socket_sessions = context2.socket(zmq.PUB)
socket_sessions.bind("tcp://*:5557")


def send_array(socket, A, session="buq123", flags=0, copy=False, track=False):
    """send a numpy array with metadata"""
    md = dict(
        dtype = str(A.dtype),
        shape = A.shape,
    )
    socket.send_string(f"{session} Plot{np.random.randint(3)} 111", flags|zmq.SNDMORE) # Session name, plot name, subplot number
    socket.send_json(md, flags|zmq.SNDMORE) # Array metadata
    return socket.send(A, flags, copy=copy, track=track) # Array data
github alisw / AliRoot / HLT / BASE / util / ZMQmonitor.py View on Github external
,payloadSize
            )
    theMessage[idx]=header

#  Prepare our context and sockets
context = zmq.Context()

if mode=="PUSH":
    socket = context.socket(zmq.PUSH)
elif mode=="PULL":
    socket = context.socket(zmq.PULL)
elif mode=="SUB":
    socket = context.socket(zmq.SUB)
    socket.setsockopt(zmq.SUBSCRIBE, theMessage[0])
elif mode=="PUB":
    socket = context.socket(zmq.PUB)
elif mode=="REQ":
    socket = context.socket(zmq.REQ)
elif mode=="REP":
    socket = context.socket(zmq.REP)
else:
    print "not a valid mode"
    quit()
#socket.set(zmq.LINGER,10)
if endpoint[0]=='>' or endpoint[0]=='-' or endpoint[0]=='+':
    print "connect to: "+endpoint[1:]
    socket.connect(str(endpoint[1:]))
elif endpoint[0]=='@':
    print "bind to: "+endpoint[1:]
    socket.bind(str(endpoint[1:]))

# fill in the header information
github sailfish-team / sailfish / utils / visualizer.py View on Github external
def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Sailfish viewer')

        self._ctx = zmq.Context()
        self._ui_sock = self._ctx.socket(zmq.PUB)
        self._ui_sock.bind('inproc://ui')
        self._last_transpose = False

        Publisher().subscribe(self.OnData, "update")
        Publisher().subscribe(self.OnInit, "init")
        DataThread(self, self._ctx).start()

        # UI setup.
        self.figure = Figure(figsize=(4,3), dpi=100)
        self.canvas = FigureCanvas(self, -1, self.figure)

        # Slice position control.
        self.position = wx.SpinCtrl(self, style=wx.TE_PROCESS_ENTER |
                                    wx.SP_ARROW_KEYS)
        self.position.Bind(wx.EVT_SPINCTRL, self.OnPositionChange)
        self.position.Bind(wx.EVT_TEXT_ENTER, self.OnPositionChange)
github fp7-netide / Tools / debugger / Core / verificator_runtime_ide.py View on Github external
elif (n == "3"):
         #receive_messages(module_list, address_list)
         print_list_address(address_list)


def main():

   module_list = []
   address_list = []
   loop = False
   thread.start_new_thread(receive_messages, (module_list, address_list,))
   thread.start_new_thread(receive_commands, (module_list, address_list))
   menu(module_list, address_list, loop)

context = zmq.Context()
ide_socket = context.socket(zmq.PUB)
ide_socket.bind("tcp://*:5560")
main()
github zeromq / pyzmq / examples / chat / prompt.py View on Github external
def main(addr, who):

    ctx = zmq.Context()
    socket = ctx.socket(zmq.PUB)
    socket.bind(addr)

    while True:
        msg = raw_input("%s> " % who)
        socket.send_pyobj((msg, who))
github domogik / domogik / src / domogik / common / mq / pubsub / mq_event_fwd.py View on Github external
log = logger.Logger('mq_event_fwd').get_logger()
    
    try:
        context = zmq.Context(1)

        # Socket facing emitters
        frontend = context.socket(zmq.SUB)
        # Forwarder subscribes to the emitter *pub* port
        sub_addr = "tcp://*:%s" % cfg_messaging['event_pub_port']
        frontend.bind(sub_addr)
        log.debug("Waiting for messages on %s" % sub_addr)
        # We want to get all messages from emitters
        frontend.setsockopt(zmq.SUBSCRIBE, "")
        
        # Socket facing receivers
        backend = context.socket(zmq.PUB)
        # Forwarder publishes to the receiver *sub* port
        pub_addr = "tcp://*:%s" % cfg_messaging['event_sub_port']
        backend.bind(pub_addr)
        log.debug("Sending messages to %s" % pub_addr)
        
        log.debug("Forwarding messages...")
        zmq.device(zmq.FORWARDER, frontend, backend)
    except Exception as e:
        log.error(e)
        log.error("Bringing down ZMQ device")
        raise Exception("Error with forwarder device")
    finally:
        pass
        frontend.close()
        backend.close()
        context.term()
github benhoff / CHATIMUSMAXIMUS / chatimusmaximus / messaging.py View on Github external
def __init__(self, parent=None):
        super().__init__(parent)
        context = zmq.Context()
        self.sub_socket = context.socket(zmq.SUB)
        self.sub_socket.setsockopt(zmq.SUBSCRIBE, b'')
        self.pub_socket = context.socket(zmq.PUB)
        self.thread = Thread(target=self._recv_sub_socket, daemon=True)
        self.thread.start()
        # service, user, msg, time
        self._last_message = ('', '', '', time.time())
github koursaros-ai / microservices / koursaros / network.py View on Github external
            SocketType.PUB_BIND: lambda: self.ctx.socket(zmq.PUB),
            SocketType.PUB_CONNECT: lambda: self.ctx.socket(zmq.PUB),
github openpowerquality / opq / mauka / services / brokers.py View on Github external
import logging
        import signal
        import os
        import zmq

        _logger = logging.getLogger("app")
        logging.basicConfig(
            format="[%(levelname)s][%(asctime)s][{} %(filename)s:%(lineno)s - %(funcName)s() ] %(message)s".format(
                os.getpid()))

        signal.signal(signal.SIGINT, signal.SIG_IGN)

        zmq_pub_interface = conf.get("zmq.mauka.broker.pub.interface")
        zmq_sub_interface = conf.get("zmq.mauka.broker.sub.interface")
        zmq_context = zmq.Context()
        zmq_pub_socket = zmq_context.socket(zmq.PUB)
        zmq_sub_socket = zmq_context.socket(zmq.SUB)
        zmq_pub_socket.bind(zmq_pub_interface)
        zmq_sub_socket.bind(zmq_sub_interface)
        zmq_sub_socket.setsockopt(zmq.SUBSCRIBE, b"")

        _logger.info("Starting Mauka pub/sub broker")
        zmq.proxy(zmq_sub_socket, zmq_pub_socket)
        _logger.info("Exiting Mauka pub/sub broker")