NATS integration for taskiq
Project description
Taskiq NATS
Taskiq-nats is a plugin for taskiq that adds NATS broker.
Installation
To use this project you must have installed core taskiq library:
pip install taskiq taskiq-redis
Usage
Here's a minimal setup example with a broker and one task.
import asyncio
from taskiq_nats import NatsBroker
broker = NatsBroker(
[
"nats://nats1:4222",
"nats://nats2:4222",
],
queue="random_queue_name",
)
@broker.task
async def my_lovely_task():
print("I love taskiq")
async def main():
await broker.startup()
await my_lovely_task.kiq()
await broker.shutdown()
if __name__ == "__main__":
asyncio.run(main())
NatsBroker configuration
Here's the constructor parameters:
servers
- a single string or a list of strings with nats nodes addresses.subject
- name of the subect that will be used to exchange tasks betwee workers and clients.queue
- optional name of the queue. By default NatsBroker broadcasts task to all workers, but if you want to handle every task only once, you need to supply this argument.result_backend
- custom result backend.task_id_generator
- custom function to generate task ids.- Every other keyword argument will be sent to
nats.connect
function.
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
taskiq_nats-0.1.2.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for taskiq_nats-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e4efc87c4cda05adabe8d3334eb27b783c56fb88c0f299064472f14198f6c1 |
|
MD5 | 7c9e391ff617460756b9668663f505fb |
|
BLAKE2b-256 | 0ae1e2153a4685def1c7dfc235f2503ab352262535667700c9c07c9dd1d8a4ed |