Fedora Messaging
raw JSON → 3.9.0 verified Mon Apr 27 auth: no python
A set of tools for using Fedora's messaging infrastructure, based on RabbitMQ and AMQP. Current version 3.9.0, updated frequently with releases every few months.
pip install fedora-messaging Common errors
error ModuleNotFoundError: No module named 'fedora_messaging.twisted' ↓
cause The 'twisted' extra is not installed. The twisted submodule requires optional dependencies.
fix
pip install fedora-messaging[twisted]
error KeyError: 'amqp_url' ↓
cause Configuration was not set before calling connect().
fix
Set config.conf['amqp_url'] = 'your_url' before calling connect().
Warnings
breaking Version 3.0 removed the 'fedora_messaging.twisted.service' module; use 'fedora_messaging.twisted.service_factory' instead. ↓
fix Replace imports of fedora_messaging.twisted.service with fedora_messaging.twisted.service_factory.
deprecated The 'fedora_messaging.message.Message' class is deprecated in favor of schema-based messages. Use 'from fedora_messaging.message import Message' will still work but emit a deprecation warning. ↓
fix Use fedora_messaging.schema.Message or define custom messages via schema.
gotcha The configuration file must be loaded before any other imports or calls. Calling config.setup() is not enough; use config.conf to set options directly. ↓
fix Set config.conf['key'] = value before importing other modules that use configuration.
Imports
- twisted wrong
import fedora_messaging.twistedcorrectfrom fedora_messaging import twisted - connect wrong
from fedora_messaging import connectcorrectfrom fedora_messaging.api import connect
Quickstart
from fedora_messaging import config
from fedora_messaging.api import connect, consume
# Configure connection
config.conf['amqp_url'] = 'amqp://guest:guest@localhost:5672/%2F'
# Define a callback
def callback(message):
print(f"Received: {message.body}")
# Consume a queue
with connect() as connection:
consume(connection, callback, queue='my_queue')