amqpstorm library for Flask
Project description
AMQP Service for Flask Apps
Features
- Connection validation and reconnection for AMQP.
- Sending messages to a specified exchange with retries.
- Consuming messages from a queue with retries.
- Customizable parameters for exchanges and queues.
- Message headers and properties support.
- Multi-threading support for consumers.
Prerequisites
- Python 3.x
- Flask
- amqpstorm
- retry
Installation
To install the required dependencies, run:
pip install Flask amqpstorm retry
pip install amqpstorm-flask
Usage
Initialization
First, create a Flask app and initialize the AmqpService
.
from flask import Flask
app = Flask(__name__)
app.config["MQ_URL"] = "<Your_MQ_URL>"
app.config["MQ_EXCHANGE"] = "<Your_MQ_Exchange_Name>"
amqp_service = AmqpService()
amqp_service.init_app(app)
Sending Messages
To send a message to a specified exchange:
amqp_service.send(
body={"key": "value"},
routing_key="route.key",
exchange_type="direct",
retries=5,
)
Consuming Messages
To consume messages from a specified queue:
@amqp_service.queue_consumer(
queue_name="test_queue",
routing_key="route.key",
)
def process_message(message):
print(message.body)
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
amqpstorm_flask-0.0.2.tar.gz
(19.5 kB
view hashes)
Built Distribution
Close
Hashes for amqpstorm_flask-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b7922ff1ba9c2e4d2193c912c18fc97ec85a2c9278bfc871859b1deedb73ee |
|
MD5 | 7e7f4bee9ff8d555ad0252e6a1ffca50 |
|
BLAKE2b-256 | db2eec5c434180acc501a1c475dde2d908ee7f63211e06b9f6ae75102235a3b6 |