Ejemplo n.º 1
0
    def test_consumer(self):
        nsq = yield from create_nsq(host=self.host, port=self.port,
                                    heartbeat_interval=30000,
                                    feature_negotiation=True,
                                    tls_v1=True,
                                    snappy=False,
                                    deflate=False,
                                    deflate_level=0,
                                    loop=self.loop)
        for i in range(0, 100):
            yield from nsq.pub(b'foo', b'xxx:i')

        yield from asyncio.sleep(0.1, loop=self.loop)
        consumer = NsqConsumer(nsqd_tcp_addresses=[(self.host, self.port)],
                               max_in_flight=30, loop=self.loop)
        yield from consumer.connect()
        yield from consumer.subscribe(b'foo', b'bar')

        msgs = []
        for i, waiter in enumerate(consumer.wait_messages()):

            # yield from msg.fin()
            print('-----msgs', len(msgs))
            is_starved = consumer.is_starved()


            if is_starved:
                print(">>>>>>>>msgs in list: {}".format(len((msgs))))
                for m in msgs:
                    yield from m.fin()
                msgs = []

            msg = yield from waiter
            msgs.append(msg)
Ejemplo n.º 2
0
    def _poll_lookupd(self, host, port):
        conn = NsqLookupd(host, port, loop=self.loop)
        res = yield from conn.lookup('foo')

        for producer in res['producers']:
            host = producer['broadcast_address']
            port = producer['tcp_port']
            conn = yield from create_nsq(host, port, queue=self._queue,
                                         loop=self._loop)
            self._connections[conn.id] = conn
        conn.close()
Ejemplo n.º 3
0
    def connect(self):
        if self._lookupd_http_addresses:
            self._lookupd_task = asyncio.Task(self._lookupd(), loop=self._loop)

        if self._nsqd_tcp_addresses:
            for host, port in self._nsqd_tcp_addresses:
                conn = yield from create_nsq(host, port, queue=self._queue,
                                             loop=self._loop)
            self._connections[conn.id] = conn


        self._rdy_control = RdyControl(idle_timeout=self._idle_timeout,
                                       max_in_flight=self._max_in_flight,
                                       loop=self._loop)
        self._rdy_control.add_connections(self._connections)
Ejemplo n.º 4
0
    def go():
        nsq = yield from create_nsq(host='127.0.0.1', port=4150,
                                    heartbeat_interval=30000,
                                    feature_negotiation=True,
                                    tls_v1=False,
                                    # snappy=True,
                                    # deflate=True,
                                    deflate_level=0,
                                    loop=loop)

        yield from nsq.pub(b'foo', b'msg foo')
        yield from nsq.sub(b'foo', b'bar')
        yield from nsq.rdy(1)
        msg = yield from nsq.wait_messages()
        assert not msg.processed
        yield from msg.fin()
        print(msg)
        assert msg.processed
        yield from nsq.cls()
Ejemplo n.º 5
0
    def go():
        nsq_producer = yield from create_nsq(host='localhost', port=4150,
                            heartbeat_interval=30000,
                            feature_negotiation=True,
                            tls_v1=True,
                            snappy=False,
                            deflate=False,
                            deflate_level=0,
                            loop=loop)
        for i in range(0, 35):
            yield from nsq_producer.pub(b'foo', 'xxx:{}'.format(i))


        endpoints = [('localhost', 4150)]
        nsq_consumer = NsqConsumer(nsqd_tcp_addresses=endpoints, loop=loop)
        yield from nsq_consumer.connect()
        yield from nsq_consumer.subscribe(b'foo', b'bar')
        for waiter in nsq_consumer.wait_messages():
            message = yield from waiter
            print(message)
            yield from message.fin()