Written with native Asyncio NSQ package
Project description
ansq - Async NSQ
Written with native Asyncio NSQ package
Installation
python -m pip install ansq
Overview
Reader— high-level class for building consumers withnsqlookupdsupportWriter— high-level producer class supporting async publishing of messages tonsqdover the TCP protocolNSQConnection— low-level class representing a TCP connection tonsqd:- full TCP wrapper
- one connection for
subandpub - self-healing: when the connection is lost, reconnects, sends identify and auth commands, subscribes to previous topic/channel
Features
- SUB
- PUB
- Discovery
- Backoff
- TLS
- Deflate
- Snappy
- Sampling
- AUTH
Usage
Consumer
A simple consumer reads messages from "example_topic" and prints them to stdout.
import asyncio
import ansq
async def main():
reader = await ansq.create_reader(
topic="example_topic",
channel="example_channel",
)
async for message in reader.messages():
print(f"Message: {message.body}")
await message.fin()
await reader.close()
if __name__ == "__main__":
asyncio.run(main())
Producer
A simple producer sends a "Hello, world!" message to "example_topic".
import asyncio
import ansq
async def main():
writer = await ansq.create_writer()
await writer.pub(
topic="example_topic",
message="Hello, world!",
)
await writer.close()
if __name__ == "__main__":
asyncio.run(main())
Contributing
Create and activate a development virtual environment.
python -m venv venv
source venv/bin/activate
Install ansq in editable mode and its testing dependencies.
python -m pip install -e .[testing]
Run tests.
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ansq-0.3.0.tar.gz.
File metadata
- Download URL: ansq-0.3.0.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec35ad42eed8f100ac0f14067b1bda43938b68de22bc0f22ec990e05036dabfb
|
|
| MD5 |
0f23f11e7f3fab66527c6c9f56825539
|
|
| BLAKE2b-256 |
418992a1027653401655a947b755ae17e857623d62305ef14e75b71894a217cc
|
File details
Details for the file ansq-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ansq-0.3.0-py3-none-any.whl
- Upload date:
- Size: 28.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40659c6b25aef0e03608aadf6b4c78f235273afafd8b002bfde8f0e1d64ade36
|
|
| MD5 |
4c7848709eb63d4f3a4528f82fb31ad1
|
|
| BLAKE2b-256 |
258083aca9e509ac0c34c19adae8d7cce36db89d7f0aba7a3d070ee4c05b6da7
|