def _(lookupd_server, nsqd_server): lookupd = gnsq.Lookupd(lookupd_server.http_address) conn = gnsq.Nsqd(nsqd_server.address, http_port=nsqd_server.http_port) assert len(lookupd.topics()['topics']) == 0 assert len(lookupd.channels('topic')['channels']) == 0 assert len(lookupd.nodes()['producers']) == 1 conn.create_topic('topic') gevent.sleep(0.1) info = lookupd.lookup('topic') assert len(info['channels']) == 0 assert len(info['producers']) == 1 assert len(lookupd.topics()['topics']) == 1 assert len(lookupd.channels('topic')['channels']) == 0 conn.create_channel('topic', 'channel') gevent.sleep(0.1) info = lookupd.lookup('topic') assert len(info['channels']) == 1 assert len(info['producers']) == 1 assert len(lookupd.topics()['topics']) == 1 assert len(lookupd.channels('topic')['channels']) == 1
def __init__(self, name, event, queue, config, channel="default"): threading.Thread.__init__(self) self.name = name self.event = event self.config = config self.queue = queue self.timeout = int(self.config["connection"]["timeout"]) self.max_tries = int(self.config["connection"]["max_tries"]) nsqlookup_url = "{}:{}".format(self.config["nsqlookupd"]["ip"], self.config["nsqlookupd"]["port"]) self.reader = gnsq.Reader( message_handler=self.message_handler, lookupd_http_addresses=nsqlookup_url, lookupd_poll_interval=self.config["nsqlookupd"]["interval"], topic=self.config["topics"]["data_topic"], channel=channel) self.writer = gnsq.Nsqd(address=self.config["nsqd"]["ip"], http_port=self.config["nsqd"]["port"]) self.lookup = gnsq.Lookupd(address=nsqlookup_url) logger.info("{} initialized successfully".format(self.name))
def test_lookup(): with LookupdIntegrationServer() as lookupd_server: nsqd_server = NsqdIntegrationServer(lookupd=lookupd_server.tcp_address) with NsqdIntegrationServer( lookupd=lookupd_server.tcp_address) as nsqd_server: lookupd = gnsq.Lookupd(lookupd_server.http_address) conn = gnsq.Nsqd(nsqd_server.address, http_port=nsqd_server.http_port) gevent.sleep(0.1) assert len(lookupd.topics()['topics']) == 0 assert len(lookupd.channels('topic')['channels']) == 0 assert len(lookupd.nodes()['producers']) == 1 conn.create_topic('topic') gevent.sleep(0.1) info = lookupd.lookup('topic') assert len(info['channels']) == 0 assert len(info['producers']) == 1 assert len(lookupd.topics()['topics']) == 1 assert len(lookupd.channels('topic')['channels']) == 0 conn.create_channel('topic', 'channel') gevent.sleep(0.1) info = lookupd.lookup('topic') assert len(info['channels']) == 1 assert len(info['producers']) == 1 assert len(lookupd.topics()['topics']) == 1 assert len(lookupd.channels('topic')['channels']) == 1
def test_basic(): with LookupdIntegrationServer() as server: lookupd = gnsq.Lookupd(server.http_address) assert lookupd.ping() == 'OK' assert 'version' in lookupd.info() with pytest.raises(gnsq.errors.NSQHttpError): lookupd.lookup('topic') assert len(lookupd.topics()['topics']) == 0 assert len(lookupd.channels('topic')['channels']) == 0 assert len(lookupd.nodes()['producers']) == 0
def __init__(self, name, event, queue, config): threading.Thread.__init__(self) self.name = name self.config = config self.event = event self.queue = queue self.timeout = int(self.config["connection"]["timeout"]) self.max_tries = int(self.config["connection"]["max_tries"]) nsqlookup_url = "{}:{}".format(self.config["nsqlookupd"]["ip"], self.config["nsqlookupd"]["port"]) self.writer = gnsq.Nsqd(address=self.config["nsqd"]["ip"], http_port=self.config["nsqd"]["port"]) self.lookup = gnsq.Lookupd(address=nsqlookup_url) logger.info("{} initialized successfully".format(self.name))