Migrating from Django
Migrating from Django
Flask-RMQ preserves the messaging model while replacing Django lifecycle and management APIs.
| Django application | Flask-RMQ |
|---|---|
AppConfig.ready() | FlaskRMQ.init_app(app) |
Django settings.RABBITMQ_CONNECTIONS | app.config['RABBITMQ_CONNECTIONS'] |
manage.py setup_rabbitmq | flask --app ... rmq setup |
manage.py start_consumers | flask --app ... rmq consume |
django.core.exceptions.ImproperlyConfigured | flask_rmq.ConfigurationError |
automatic close_old_connections() | ORM-specific cleanup in the application handler |
Producer, Consumer, QueueConfig, aliases, registries, callbacks, publisher confirms, DLX behavior, and reconnect rules remain conceptually equivalent.
Registration
Django registration commonly happens in AppConfig.ready(). In Flask, initialize configuration first and register in the factory:
def create_app():
app = Flask(__name__)
app.config.from_object(Config)
rmq.init_app(app)
with app.app_context():
get_setup_registry().register(setup_topology)
get_consumers_registry().register(consumer)
return appHandler context
Consumer threads receive a Flask application context, not a request context. current_app and extension proxies are available; request, session cookies, and request-scoped data are not. Pass all required business context in the message or load it by stable identifiers.