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.request_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.dev36.tar.gz
(11.5 kB
view details)
Built Distribution
File details
Details for the file mqtasks-0.0.1.dev36.tar.gz
.
File metadata
- Download URL: mqtasks-0.0.1.dev36.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a819f6940f243b45c87dadc04fb6dc64d814198b117f876482bc1a0842d9cfeb |
|
MD5 | 4e2d81a3c53cc3af19fa63a2b06cd8cd |
|
BLAKE2b-256 | 0cd192b62bec3bf25217b289d97acaec11fae0cb12b54e012e131f482e0c2ba9 |
File details
Details for the file mqtasks-0.0.1.dev36-py3-none-any.whl
.
File metadata
- Download URL: mqtasks-0.0.1.dev36-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 341ade2e83505b83dda2282cff0dd5b2eb3c9f0b1d07308519796362e568ae9a |
|
MD5 | 3499d4b39c37ac17bacb9111dcf358c5 |
|
BLAKE2b-256 | 173f131c22a42eeedf2da69d7e1a81abfdf22decf5bff1081b4d41da9e2e2fee |