Skip to main content

asyncio async/await nsq support

Project description

nsqio

Downloads Downloads Downloads PyPI version

if you dont like the pynsq(which use tornado) way to interact with nsq, then this library may be suitable for you

you can use this library as the common way to write things

Important

  • it is not stable yet

Features


Http Client

  • support all the method nsq http supplied

Tcp Client

Connection

  • low level connection.

Reader

  • reader from both lookupd for auto finding nsqd

  • list of known nsqd but they can not use together.

  • above two can't use together

Writer

  • all the common method for nsqd writer

Next Features

different reader protocol support

more doc to write

more tests

Install


pip install nsqio

Usage examples


All you need is a loop, then enjoy. you can refer to examples, as well.

Consumer:

from nsqio import create_reader
from nsqio.utils import get_logger

loop = asyncio.get_event_loop()
async def go():
    try:
        reader = await create_reader(
            nsqd_tcp_addresses=['127.0.0.1:4150'],
            max_in_flight=200)
        await reader.subscribe('test_async_nsq', 'nsq')
        async for message in reader.messages():
            print(message.body)
            await message.fin()
    except Exception as tmp:
        self.logger.exception(tmp)
loop.run_until_complete(go())

Producer:

from nsqio import create_writer
loop = asyncio.get_event_loop()
async def go():
    writer = await create_writer(host='127.0.0.1', port=4150,
                                       heartbeat_interval=30000,
                                       feature_negotiation=True,
                                       tls_v1=True,
                                       snappy=False,
                                       deflate=False,
                                       deflate_level=0,
                                       loop=loop)
    for i in range(100):
        await writer.pub('test_async_nsq', 'test_async_nsq:{i}'.format(i=i))
        await writer.dpub('test_async_nsq', i * 1000,
                                'test_delay_async_nsq:{i}'.format(i=i))
loop.run_until_complete(go())

Requirements

  • Python_ 3.6+ https://www.python.org

  • nsq_ http://nsq.io

  • python-snappy

    1. ubuntu:
      • sudo apt-get install libsnappy-dev
      • pip install python-snappy
    2. centos:
      • sudo yum install snappy-devel
      • pip install python-snappy
    3. mac:
      • brew install snappy # snappy library from Google
      • CPPFLAGS="-I/usr/local/include -L/usr/local/lib" pip install python-snappy

License

The nsqio is offered under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsqio-0.0.12.tar.gz (18.7 kB view details)

Uploaded Source

File details

Details for the file nsqio-0.0.12.tar.gz.

File metadata

  • Download URL: nsqio-0.0.12.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

File hashes

Hashes for nsqio-0.0.12.tar.gz
Algorithm Hash digest
SHA256 91747bc9614108d2abc21514e20d8448dc087d8623e59f8aba0af2063f908c8e
MD5 277fd803cc65d72e5db4729b0e4d71d6
BLAKE2b-256 941ff021c7d6de92d46bb19d597acf261a73406ec1db6061f0dab389ab76b76b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page