This module provides a framework for handling and processing asynchronous tasks through message queues.
Project description
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.run_task_async(task_name="my_task", body={"message":"hello world"})
Examples:
How to start example:
- Work dir:
./example
cd ./example
- Start RabbitMQ
docker pull rabbitmq:management
docker 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
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mqtasks-0.0.1.dev16.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file mqtasks-0.0.1.dev16.tar.gz
.
File metadata
- Download URL: mqtasks-0.0.1.dev16.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a85fa9a7fa7642c8b1d7cf6e185ccf5e53b16fe6951bbffd2caedfa14b9af7 |
|
MD5 | e95b3001edd2b1ffb573d931a89e5d06 |
|
BLAKE2b-256 | 3b3d9f8a2484ade5e58329535d6dab3e862001075245dbde826f6a298ed729f1 |
File details
Details for the file mqtasks-0.0.1.dev16-py3-none-any.whl
.
File metadata
- Download URL: mqtasks-0.0.1.dev16-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd2a79b26c6a0d4715f562723e18972fa64760f71b05baee1adddc8a83bc64d0 |
|
MD5 | 1e1bfa9a2358210afdcaf79e2e0bc7b7 |
|
BLAKE2b-256 | ed5eb734ae4079066a919120e747990aa9196982a0a10ea4484c260e6ea3a829 |