예제 #1
0
파일: simple.py 프로젝트: jettify/aionsq
    def go():
        nsq = yield from create_connection(port=4150, loop=loop)
        resp = yield from nsq.identify(
            **{
                "client_id": "metrics_increment",
                "hostname": "localhost",
                "heartbeat_interval": 30000,
                "feature_negotiation": True,
                "tls_v1": True,
                # "snappy": True,
                # "sample_rate": 50,
                "deflate": True, "deflate_level": 6,
            })
        # resp = yield from nsq.execute(b'IDENTIFY',
        # data=json.dumps({"tls_v1": True}))

        print(resp)
        for i in range(0, 100):
            d = b'test_msg: ' + bytes([i])
            print('send ', i, '-----', d)
            yield from nsq.execute(b'PUB', b'foo', data=d)

        yield from nsq.execute(b'SUB', b'foo', b'bar')

        for i in range(0, 50):
            yield from nsq.execute(b'RDY', b'1')
            msg = yield from nsq._msq_queue.get()
            yield from nsq.execute(b'FIN', msg.message_id)
예제 #2
0
    def test_tls(self):
        conn = yield from create_connection(host=self.host, port=self.port,
                                            loop=self.loop)

        config = {'feature_negotiation':True, 'tls_v1': True,
                  'snappy': False, 'deflate': False
        }

        yield from conn.identify(**config)
        yield from self._pub_sub_rdy_fin(conn)
예제 #3
0
 def test_basic_instance(self):
     host, port = '127.0.0.1', 4150
     nsq = yield from create_connection(host=host, port=port,
                                        loop=self.loop)
     self.assertIsInstance(nsq, NsqConnection)
     self.assertTrue('NsqConnection' in nsq.__repr__())
     self.assertTrue(not nsq.closed)
     self.assertTrue(host in nsq.endpoint)
     self.assertTrue(str(port) in nsq.endpoint)
     nsq.close()
     self.assertEqual(nsq.closed, True)
예제 #4
0
    def test_deflate(self):
        conn = yield from create_connection(host=self.host, port=self.port,
                                            loop=self.loop)

        config = {'feature_negotiation':True, 'tls_v1': False,
                  'snappy': False, 'deflate': True
        }
        self.assertIsInstance(conn._parser, Reader)

        yield from conn.identify(**config)
        self.assertIsInstance(conn._parser, DeflateReader)
        yield from self._pub_sub_rdy_fin(conn)
예제 #5
0
    def test_message(self):
        conn = yield from create_connection(host=self.host, port=self.port,
                                            loop=self.loop)

        ok = yield from conn.execute(b'PUB', self.topic, data=b'boom')
        self.assertEqual(ok, b'OK')
        yield from conn.execute(b'SUB', self.topic,  b'bar')
        yield from conn.execute(b'RDY', 1)


        msg = yield from conn._queue.get()
        self.assertEqual(msg.processed, False)

        yield from msg.touch()
        self.assertEqual(msg.processed, False)
        yield from msg.req(1)
        self.assertEqual(msg.processed, True)
        yield from conn.execute(b'RDY', 1)
        new_msg = yield from conn._queue.get()
        yield from new_msg.fin()
        self.assertEqual(msg.processed, True)

        yield from conn.execute(b'CLS')
예제 #6
0
    def test_pub_sub(self):
        conn = yield from create_connection(host=self.host, port=self.port,
                                            loop=self.loop)

        yield from self._pub_sub_rdy_fin(conn)