Skip to content

Commit b63c73e

Browse files
committed
Updated README.
Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent 57870d3 commit b63c73e

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Taskiq NATS
2+
3+
Taskiq-nats is a plugin for taskiq that adds NATS broker.
4+
5+
## Installation
6+
7+
To use this project you must have installed core taskiq library:
8+
9+
```bash
10+
pip install taskiq taskiq-redis
11+
```
12+
13+
## Usage
14+
15+
Here's a minimal setup example with a broker and one task.
16+
17+
```python
18+
import asyncio
19+
from taskiq_nats import NatsBroker
20+
21+
broker = NatsBroker(
22+
[
23+
"nats://nats1:4222",
24+
"nats://nats2:4222",
25+
],
26+
queue="random_queue_name",
27+
)
28+
29+
30+
@broker.task
31+
async def my_lovely_task():
32+
print("I love taskiq")
33+
34+
35+
async def main():
36+
await broker.startup()
37+
38+
await my_lovely_task.kiq()
39+
40+
await broker.shutdown()
41+
42+
43+
if __name__ == "__main__":
44+
asyncio.run(main())
45+
46+
```
47+
48+
## NatsBroker configuration
49+
50+
Here's the constructor parameters:
51+
52+
* `servers` - a single string or a list of strings with nats nodes addresses.
53+
* `subject` - name of the subect that will be used to exchange tasks betwee workers and clients.
54+
* `queue` - optional name of the queue. By default NatsBroker broadcasts task to all workers,
55+
but if you want to handle every task only once, you need to supply this argument.
56+
* `result_backend` - custom result backend.
57+
* `task_id_generator` - custom function to generate task ids.
58+
* Every other keyword argument will be sent to `nats.connect` function.

0 commit comments

Comments
 (0)