Skip to main content

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)

Uploaded Source

Built Distribution

taskiq_nats-0.1.2-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

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