How to use txZMQ - 10 common examples

To help you get started, we’ve selected a few txZMQ 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 mokshaproject / moksha / moksha.hub / moksha / hub / zeromq / zeromq.py View on Github external
# Factory used to lazily produce subsequent subscribers
        self.twisted_zmq_factory = txzmq.ZmqFactory()

        # Establish a list of subscription endpoints for later use
        _endpoints = self.config['zmq_subscribe_endpoints'].split(',')
        method = self.config.get('zmq_subscribe_method', 'connect')

        if method == 'bind':
            _endpoints = sum(map(list, map(hostname2ipaddr, _endpoints)), [])
        else:
            # Required for zeromq-3.x.
            _endpoints = sum(map(list, map(splat2ipaddr, _endpoints)), [])

        self.sub_endpoints = [
            txzmq.ZmqEndpoint(method, ep) for ep in _endpoints
        ]

        # This is required so that the publishing socket can fully set itself
        # up before we start trying to send messages on it.  This is a
        # documented zmq issue that they do not plan to fix.
        time.sleep(1)

        super(ZMQHubExtension, self).__init__()
github PyAr / lalita / lalita / plugins / zmq_proxy.py View on Github external
def init(self, config):
        self._plugins = {}
        self.config = config
        pub_address = self.config['events_address']
        cmd_address = self.config['bot_address']
        self.commands = set() # hold all the commands
        self.ctx = zmq.Context.instance()
        self.pub_socket = self.ctx.socket(zmq.PUB)
        self.pub_socket.bind(pub_address)
        # callback/command socket
        zmq_factory = ZmqFactory(context=self.ctx)
        rpc_endpoint = ZmqEndpoint("bind", cmd_address)
        self.cmd_socket = BotConnection(self, zmq_factory, rpc_endpoint)
        self.cmd_socket.subscribe("")
        for event, info in EVENT_MAP.items():
            if event != events.COMMAND:
                self.register(event, EventHandler(self, *info), re.compile(".*"))
github leapcode / bitmask_client / src / leap / bitmask / cli / command.py View on Github external
def __init__(self):
        color_init()
        zf = ZmqFactory()
        e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
        self._conn = ZmqREQConnection(zf, e)

        self.data = []
        if self.service:
            self.data = [self.service]
github leapcode / bitmask_client / src / leap / bitmask / cli / command.py View on Github external
def __init__(self):
        color_init()
        zf = ZmqFactory()
        e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
        self._conn = ZmqREQConnection(zf, e)

        self.data = []
        if self.service:
            self.data = [self.service]
github leapcode / bitmask-dev / src / leap / bitmask / cli / command.py View on Github external
def __init__(self, cfg, print_json=False):
        self.cfg = cfg

        color_init()
        zf = ZmqFactory()
        e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
        self._conn = ZmqREQConnection(zf, e)

        self.data = []
        if self.service:
            self.data = [self.service]
        self.print_json = print_json
github leapcode / bitmask-dev / src / leap / bitmask / cli / command.py View on Github external
def __init__(self, cfg, print_json=False):
        self.cfg = cfg

        color_init()
        zf = ZmqFactory()
        e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
        self._conn = ZmqREQConnection(zf, e)

        self.data = []
        if self.service:
            self.data = [self.service]
        self.print_json = print_json
github brotchie / ib-zmq / ibzmq / proxy.py View on Github external
def writeField(self, field):
        self.transport.write(str(field) + self.delimiter)

    def writeFields(self, fields):
        assert fields, 'Cannot write zero count fields.'
        self.transport.write(self.delimiter.join(map(str, fields)) + self.delimiter)

    def writeMessage(self, msg):
        self.transport.write(msg)

ZMQ_OK_RESPONSE  = 'OK'
ZMQ_ERR_RESPONSE = 'ERR'

ZMQ_OOB_PREFIX = 'OOB'

class ZmqRequests(ZmqREPConnection):
    _twsprotocol = None

    def setTWSProtocol(self, protocol):
        self._twsprotocol = protocol

    def gotMessage(self, messageid, msg):
        # Handle OOB messages.
        if msg.startswith(ZMQ_OOB_PREFIX + '\0'):
            fields = msg.split('\0')
            if fields[1] == 'NOP':
                log.debug('Sending NOP response.')
                self.reply_ok(messageid)
            else:
                log.error('Unrecognized out-of-band message {0}.'.format(msg))
                self.reply_err(messageid)
        else:
github erikkaplun / spinoff / unnamedframework / actor / zmqdemo / zmqdemo.py View on Github external
print 'got message: ', msg
            yield sleep(3.0 + random.random())


class ZmqTestServer(Process):

    @inlineCallbacks
    def start(self):
        while True:
            req = yield self.get()
            print 'got request: ', req
            yield sleep(5.0)
            self.put(req)


f = ZmqFactory()


client1 = ZmqTestClient()
client2 = ZmqTestClient()
client3 = ZmqTestClient()
server = ZmqTestServer()

application = Application(
    Pipeline(
        client1,
        ZmqReq(f, 'ipc://foobar', 'client1'),
        client1,
        ),

    Pipeline(
        client2,
github erikkaplun / spinoff / spinoff / actor / zmqdemo / zmqdemo3 / server.py View on Github external
while True:
            if not self._routing_info:
                yield sleep(.1)
                continue
            agent_id, transport_id = random.choice(self._routing_info.items())
            print "SERVER: send job to agent %s @ ZMQ identity %s" % (agent_id, repr(transport_id))
            self.put((transport_id, 'job'), outbox='jobs')
            yield sleep(1.0)

    def stop(self):
        print "SERVER: going down"
        for _, transport_id in self._routing_info.items():
            self.put((transport_id, 'server-going-down'), outbox='ctrl')


f = ZmqFactory()

SERVER_ADDR = 'ipc://server'


server = TestServer()
server_transport = ZmqRouter(f, SERVER_ADDR)

server.connect(['ctrl', 'jobs'], server_transport)
server_transport.connect('ctrl', server)


application = Application(
    [server]
    )
github leapcode / leap_pycommon / src / leap / common / events / zmq_components.py View on Github external
def __init__(self, path_prefix=None):
        """
        Initialize the txzmq component.
        """
        self._factory = txzmq.ZmqFactory()
        self._factory.registerForShutdown()
        if path_prefix is None:
            path_prefix = get_path_prefix(flags.STANDALONE)
        self._config_prefix = os.path.join(path_prefix, "leap", "events")
        self._connections = []