Configuration
Configuration
FlaskRMQ.init_app() reads RABBITMQ_CONNECTIONS. The shape mirrors Flask's common extension configuration style: aliases at the top level, connection fields below.
app.config["RABBITMQ_CONNECTIONS"] = {
"default": {
"HOST": "rabbitmq.internal",
"PORT": 5672,
"VIRTUAL_HOST": "/orders",
"USER": "orders-service",
"PASSWORD": os.environ["RABBITMQ_PASSWORD"],
"HEARTBEAT": 600,
"BLOCKED_CONNECTION_TIMEOUT": 300,
"RECONNECT_INITIAL_BACKOFF": 1.0,
"RECONNECT_MAX_BACKOFF": 30.0,
},
"analytics": {
"HOST": "analytics-rabbitmq.internal",
"USER": "publisher",
"PASSWORD": os.environ["ANALYTICS_RABBITMQ_PASSWORD"],
},
}| Key | Default | Meaning |
|---|---|---|
HOST | required | Broker hostname or IP. |
PORT | 5672 | AMQP TCP port. |
VIRTUAL_HOST | / | RabbitMQ virtual host. |
USER | guest | Username. Do not use guest remotely in production. |
PASSWORD | guest | Password; load it from secrets or environment. |
HEARTBEAT | 600 | Negotiated heartbeat interval in seconds. |
BLOCKED_CONNECTION_TIMEOUT | 300 | Fail a connection blocked by broker resource alarms after this many seconds. |
RECONNECT_INITIAL_BACKOFF | 1.0 | First consumer reconnect delay. |
RECONNECT_MAX_BACKOFF | 30.0 | Exponential-backoff cap. |
Lowercase field names are accepted as well, which is convenient when a mapping comes from a configuration service.
Alias resolution
With one configured alias, using= is optional. With two or more, it is mandatory:
audit_producer = Producer(queue="audit", using="analytics")
audit_consumer = Consumer(queue="audit", using="analytics")
get_setup_registry(using="analytics").register(setup_audit)Omitting it with multiple aliases raises ConfigurationError. This is deliberate: silently selecting a broker is a data-routing bug.
Application context
Registry and connection accessors resolve the current Flask application. Use them inside an app context. Consumer threads created by the CLI automatically receive their own context, so handlers may safely use current_app, Flask-SQLAlchemy, and other context-aware extensions.
When exactly one Flask app has been initialized, producer calls outside a context can resolve it. For multi-app processes, always push an explicit app context.