Skip to main content

Available brokers

...

Available brokers

In this section we'll list officially supported brokers.

InMemoryBroker

This is a special broker for local development. It uses the same functions to execute tasks, but all tasks are executed locally in the current thread. By default it uses InMemoryResultBackend but this can be overridden.

ZeroMQBroker

This broker uses ZMQopen in new window to communicate between worker and client processes. It's suitable for small projects with only ONE worker process, because of the ZMQ architecture.

It publishes messages on the local port. All worker processes are reading messages from this port. If you run many worker processes, all tasks will be executed N times, where N is the total number of worker processes.

Be careful!

If you choose this type of broker, please run taskiq with -w 1 parameter, otherwise you may encounter undefined behavior.

To run this broker please install the pyzmqopen in new window lib. Or you can taskiq with zmq extra.

Only PyZMQ
pip install pyzmq

Async shared broker and shared tasks

This is also a special broker. You cannot use it directly. It's used to create shared tasks. These tasks can be imported along with user defined tasks. To define a shared task please use this broker.

from taskiq.brokers.shared_broker import async_shared_broker

@async_shared_broker.task
def my_task() -> bool:
    return True

To kiq this task you have to options:

  • Explicitly define broker using kicker for this kiq;
  • Add default broker for all shared tasks.
Defining default broker
from taskiq.brokers.shared_broker import async_shared_broker

async_shared_broker.default_broker(broker)

Custom brokers

These brokers are not parts of the core taskiq lib. You can install them as a separate packages.

You can read more about parameters and abilities of these brokers in README.md of each repo.

AioPikaBroker (for RabbitMQ)

Project link: taskiq-aio-pikaopen in new window.

pip install taskiq-aio-pika

Redis broker

Project link: taskiq-redisopen in new window.

pip install taskiq-redis

NATS broker

Project link: taskiq-natsopen in new window.

pip install taskiq-nats