- 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.
- Python 3.x
- Flask
- amqpstorm
- retry
To install the required dependencies, run:
pip install amqpstorm-flask
First, create a Flask app and initialize the RabbitMQ
.
from flask import Flask
app = Flask(__name__)
app.config["MQ_URL"] = "<Your_MQ_URL>"
app.config["MQ_EXCHANGE"] = "<Your_MQ_Exchange_Name>"
amqp_service = RabbitMQ()
amqp_service.init_app(app)
To send a message to a specified exchange:
amqp_service.send(
body={"key": "value"},
routing_key="route.key",
exchange_type="direct",
retries=5,
)
To consume messages from a specified queue:
@amqp_service.queue(
queue_name="test_queue",
routing_key="route.key",
)
def process_message(message):
print(message.body)