Message Queue Tasks
This module provides a framework for handling and processing asynchronous tasks through message queues.
Overview
- Utilizes the aio_pika library for AMQP message processing.
- Offers easy-to-use decorators and methods for defining tasks, producing and consuming them.
- Built with asynchronous patterns to allow seamless scalability.
Requirements
- Python 3.11+
- aio_pika library
- RabbitMQ or other AMQP broker
Usage
1. Defining a Task
To define a task, instantiate the MqTasks object and use the task decorator:
import mqtasks
mq_tasks = MqTasks(amqp_connection="amqp://localhost", queue_name="my_queue")
@mq_tasks.task(name="my_task")
def my_task_function(ctx: MqTaskContext):
# Process task
pass
mq_tasks.run()
2. Sending a Task
Instantiate MqTasksClient and use it to send a task:
import asyncio
import mqtasks
client = MqTasksClient(
loop=asyncio.get_event_loop(),
amqp_connection="amqp://localhost"
)
# define channel
channel = await client.queue(queue_name="my_queue")
#
result = await channel.request_task_async(task_name="my_task", body={"message": "hello world"})
Examples:
How to start example:
- Work dir:
./examplecd ./example
- Start RabbitMQ
docker pull rabbitmq:managementdocker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management
- Access the RabbitMQ management web UI:
http://localhost:15672/
- By default, the credentials are:
- Username: guest
- Password: guest
- Server
python example_server.py
- Client
python example_client.py
Release
make a release/x.x.x branch, up the version and commit
change the minor version 0.X.0
./scripts/release.sh minor
change the patch version 0.0.X
./scripts/release.sh patch
merge the release/x.x.x branch into the master and the develop branch
./scripts/merge.sh
License
MIT License
Metadata
Release files for mqtasks 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mqtasks-0.2.5.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mqtasks-0.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.6 kB
Release files / mqtasks-0.2.5.tar.gz
| Download URL | mqtasks-0.2.5.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68d0f2cab9c39e447c915d023730149259fe81cceee7ed5e3b91dcb9be738f21
|
|
BLAKE2b-256 checksum How to use checksums |
4e7f871987b6aaaec619dbdf66656a24005fb1df3b9b4286e8958296f68e5ea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / mqtasks-0.2.5-py3-none-any.whl
| Download URL | mqtasks-0.2.5-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42c582c2cc950aa289fa40a16c7c947a03d9256886f50934755916831d6bd639
|
|
BLAKE2b-256 checksum How to use checksums |
fcc8eb2f216a908cdd8dab11e45aa6777c571b322cb0d50c80d5ec1a06fde130
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|