Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit README #50

Merged
merged 5 commits into from
Apr 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 76 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,85 @@

Written with native Asyncio NSQ package

## Overview
- `Reader` high-level class for building consumers with nsqlookupd support
- `Writer` high-level producer class supporting async publishing of messages to nsqd
over the TCP protocol
- `NSQConnection` - low-level class representing a TCP connection to nsqd:
- full TCP wrapper
- one connection for sub and pub
- self-healing: when the connection is lost, reconnects, sends identify
and auth commands, subscribes to previous topic/channel

## Features
* Full TCP wrapper
* One connection for writer and reader
* Self-healing: when the NSQ connection is lost, reconnects, sends identify
and auth commands, subscribes to previous topic/channel
* Many helper-methods in each class

Roadmap:
* Docs
* Lookupd tool
* HTTP API wrapper
* Deflate, Snappy compressions
* TLSv1
- [x] SUB
- [x] PUB
- [x] Discovery
- [ ] Backoff
- [ ] TLS
- [ ] Deflate
- [ ] Snappy
- [x] Sampling
- [x] AUTH

## Usages

## How to
### Consumer

## Examples
A simple consumer reads a messages from "example_topic" and prints stdout.
atugushev marked this conversation as resolved.
Show resolved Hide resolved

```python
import ansq
import asyncio


async def main():
reader = await ansq.create_reader(
nsqd_tcp_addresses=["127.0.0.1:4150"],
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__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```

### Producer

A simple producer sends a "Hello, world!" message to "example_topic".

```python
import ansq
import asyncio


async def main():
writer = await ansq.create_writer(nsqd_tcp_addresses=["127.0.0.1:4150"])
await writer.pub(
topic="example_topic",
message="Hello, world!",
)
await writer.close()


if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```

## More examples

### One connection for subscribe and publish messages
atugushev marked this conversation as resolved.
Show resolved Hide resolved

### Write and read messages:
```python
import asyncio
from ansq import open_connection
Expand Down Expand Up @@ -90,7 +150,8 @@ if __name__ == '__main__':

```

### Consumer:
### Low-level consumer

```python
import asyncio
from ansq import open_connection
Expand Down