Beispiel #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)
Beispiel #2
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()