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

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.0.1.dev18.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

mqtasks-0.0.1.dev18-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file mqtasks-0.0.1.dev18.tar.gz.

File metadata

  • Download URL: mqtasks-0.0.1.dev18.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mqtasks-0.0.1.dev18.tar.gz
Algorithm Hash digest
SHA256 daafecd5fe8c81b34ea822544e2c5e45576f15541786530930f179e75422593f
MD5 cc7b020e80eda6f5c04400500335e5e2
BLAKE2b-256 33cb0be0abf56ad7f61e69219b8a7abf8e4cb238db3547211de772ce821a8ff8

See more details on using hashes here.

File details

Details for the file mqtasks-0.0.1.dev18-py3-none-any.whl.

File metadata

File hashes

Hashes for mqtasks-0.0.1.dev18-py3-none-any.whl
Algorithm Hash digest
SHA256 87734c1c40c2b8c237b6f581113750bd6dc3d2ed2f5004bd1ec09ace48e76f08
MD5 dbe0fecd6fa4c72eaef838e4179f3497
BLAKE2b-256 4314d3a628afa4b2e94a559d16839003ea2f645c19e7836fb317970687342070

See more details on using hashes here.

Supported by

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