Metadata-Version: 2.1
Name: mqtasks
Version: 0.0.1.dev38
Summary: This module provides a framework for handling and processing asynchronous tasks through message queues.
Home-page: https://github.com/NeuralInnovations/mqtasks-python
License: MIT
Project-URL: Bug Tracker, https://github.com/NeuralInnovations/mqtasks-python/issues
Project-URL: Documentation, https://github.com/NeuralInnovations/mqtasks-python/blob/main/README.md
Project-URL: Source Code, https://github.com/NeuralInnovations/mqtasks-python
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: asyncio==3.4.*,>=3.4.3
Requires-Dist: aio_pika==9.2.*,>=9.2.2
Requires-Dist: pydantic==1.10.*,>=1.10.12
Requires-Dist: aiormq==6.7.*,>=6.7.7

# 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:
```python
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:

```python
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**
  1. ```docker pull rabbitmq:management```
  2.  ```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
