Skip to main content

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
    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

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

Project details


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.2.2.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mqtasks-0.2.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file mqtasks-0.2.2.tar.gz.

File metadata

  • Download URL: mqtasks-0.2.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mqtasks-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7cff9e6a98236c1229bace60a22dc3cb02b0723b80978606ae1f6ecdaffdf75a
MD5 30de8292293e4febbbc21917f32b4880
BLAKE2b-256 b70854b9b2a32fde81c41d64974477910a6979e2c1d10a81c1c18e093b68f9e3

See more details on using hashes here.

File details

Details for the file mqtasks-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: mqtasks-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mqtasks-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5220b2f956dd66255f9cc7f421c2fa2d5ca931045935d677096148627e1a913c
MD5 c366bdb1693b69ca1ee3521f2e729015
BLAKE2b-256 89df7c44ce1984c69ef5f96ca33c86cfd91ac47eedaeed125ec3fddef3c10a68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page