Example #1
0
    def _attach_publisher(self):
        zmq_publisher = self.args.get("zmq_publisher")

        if zmq_publisher in (None, DEFAULT_PUBLISHER):
            # if this option is not provided by the command line,
            # we ask the broker about it
            res = self.client.ping()
            endpoint = res["endpoints"]["publisher"]
            if endpoint.startswith("ipc"):
                # IPC - lets hope we're on the same box
                zmq_publisher = endpoint
            elif endpoint.startswith("tcp"):
                # TCP, let's see what IP & port we have
                splitted = split_endpoint(endpoint)
                if splitted["ip"] == "0.0.0.0":
                    # let's use the broker ip
                    broker = self.args["broker"]
                    broker_ip = split_endpoint(broker)["ip"]
                    zmq_publisher = "tcp://%s:%d" % (broker_ip, splitted["port"])
                else:
                    # let's use the original ip
                    zmq_publisher = endpoint
            else:
                zmq_publisher = DEFAULT_PUBLISHER

        self.sub.connect(zmq_publisher)
        self.zstream = zmqstream.ZMQStream(self.sub, self.loop)
        self.zstream.on_recv(self._recv_result)
        self.zmq_publisher = zmq_publisher
Example #2
0
    def _attach_publisher(self):
        zmq_publisher = self.args.get('zmq_publisher')

        if zmq_publisher in (None, DEFAULT_PUBLISHER):
            # if this option is not provided by the command line,
            # we ask the broker about it
            res = self.client.ping()
            endpoint = res['endpoints']['publisher']
            if endpoint.startswith('ipc'):
                # IPC - lets hope we're on the same box
                zmq_publisher = endpoint
            elif endpoint.startswith('tcp'):
                # TCP, let's see what IP & port we have
                splitted = split_endpoint(endpoint)
                if splitted['ip'] == '0.0.0.0':
                    # let's use the broker ip
                    broker = self.args['broker']
                    broker_ip = split_endpoint(broker)['ip']
                    zmq_publisher = 'tcp://%s:%d' % (broker_ip,
                                                     splitted['port'])
                else:
                    # let's use the original ip
                    zmq_publisher = endpoint
            else:
                zmq_publisher = DEFAULT_PUBLISHER

        self.sub.connect(zmq_publisher)
        self.zstream = zmqstream.ZMQStream(self.sub, self.loop)
        self.zstream.on_recv(self._recv_result)
        self.zmq_publisher = zmq_publisher
Example #3
0
    def _attach_publisher(self):
        zmq_publisher = self.args.get('zmq_publisher')

        if zmq_publisher in (None, DEFAULT_PUBLISHER):
            # if this option is not provided by the command line,
            # we ask the broker about it
            res = self.client.ping()
            endpoint = res['endpoints']['publisher']
            if endpoint.startswith('ipc'):
                # IPC - lets hope we're on the same box
                zmq_publisher = endpoint
            elif endpoint.startswith('tcp'):
                # TCP, let's see what IP & port we have
                splitted = split_endpoint(endpoint)
                if splitted['ip'] == '0.0.0.0':
                    # let's use the broker ip
                    broker = self.args['broker']
                    broker_ip = split_endpoint(broker)['ip']
                    zmq_publisher = 'tcp://%s:%d' % (broker_ip,
                                                     splitted['port'])
                else:
                    # let's use the original ip
                    zmq_publisher = endpoint
            else:
                zmq_publisher = DEFAULT_PUBLISHER

        self.sub.connect(zmq_publisher)
        self.zstream = zmqstream.ZMQStream(self.sub, self.loop)
        self.zstream.on_recv(self._recv_result)
        self.zmq_publisher = zmq_publisher
Example #4
0
    def test_split_endpoint(self):
        res = split_endpoint('tcp://12.22.33.45:12334')
        self.assertEqual(res['scheme'], 'tcp')
        self.assertEqual(res['ip'], '12.22.33.45')
        self.assertEqual(res['port'], 12334)

        res = split_endpoint('ipc:///here/it/is')
        self.assertEqual(res['scheme'], 'ipc')
        self.assertEqual(res['path'], '/here/it/is')

        self.assertRaises(NotImplementedError, split_endpoint,
                          'wat://ddf:ff:f')
Example #5
0
    def test_split_endpoint(self):
        res = split_endpoint('tcp://12.22.33.45:12334')
        self.assertEqual(res['scheme'], 'tcp')
        self.assertEqual(res['ip'], '12.22.33.45')
        self.assertEqual(res['port'], 12334)

        res = split_endpoint('ipc:///here/it/is')
        self.assertEqual(res['scheme'], 'ipc')
        self.assertEqual(res['path'], '/here/it/is')

        self.assertRaises(NotImplementedError, split_endpoint,
                          'wat://ddf:ff:f')