This release is a pre-release and may not be stable for production use.
Swarmauri RabbitMQ Publisher
RabbitMQPublisher is the Swarmauri PublishBase implementation for RabbitMQ. The publisher opens a pika.BlockingConnection, ensures the target exchange exists, and emits JSON payloads using persistent delivery semantics.
Highlights
- Configure using either a full AMQP URI or discrete host/port credential fields. Supplying both styles raises
ValueError. - Declares the target exchange as a durable direct exchange during instantiation.
- Serializes payloads with
json.dumpsand publishes withdelivery_mode=pika.spec.PERSISTENT_DELIVERY_MODEso messages survive broker restarts. - On
pika.exceptions.AMQPConnectionErrororChannelClosedByBrokerthe publisher reconnects once, re-declares the exchange, and retries the publish.
Installation
Choose the tool that fits your workflow:
# pip
pip install swarmauri_publisher_rabbitmq
# Poetry
poetry add swarmauri_publisher_rabbitmq
# uv
uv add swarmauri_publisher_rabbitmq
Configuration
RabbitMQPublisher extends PublishBase and supports the following fields:
| Field | Required | Description |
|---|---|---|
exchange |
Yes | The exchange name to declare and publish to. Declared as a durable direct exchange. |
uri |
Optional | Full AMQP URI. When provided, omit host/port/username/password. |
host |
Optional | RabbitMQ host. Required when uri is omitted. |
port |
Optional | RabbitMQ port. Supply the broker port (for example 5672); the publisher does not insert a default when constructing the URI. |
username |
Optional | Username used in the URI when uri is omitted. Automatically URL-encoded. |
password |
Optional | Password used in the URI when uri is omitted. Automatically URL-encoded. |
The publish(channel, payload) method treats channel as the RabbitMQ routing key. payload must be JSON serialisable because it is serialized with json.dumps before publishing.
Quickstart
Ensure RabbitMQ is reachable and that you have permission to declare the exchange. The example below shows the host/port configuration path.
# README Quickstart Example
from swarmauri_publisher_rabbitmq import RabbitMQPublisher
publisher = RabbitMQPublisher(
host="localhost",
port=5672,
username="guest",
password="guest",
exchange="demo_exchange",
)
publisher.publish(
channel="demo.routing.key",
payload={"message": "Hello RabbitMQ!"},
)
The constructor builds the AMQP URI from the supplied parts, opens a blocking connection, and declares demo_exchange as a durable direct exchange. Each call to publish JSON-encodes the payload and requests persistent delivery so the message survives broker restarts.
Connecting with an AMQP URI
If you already have an AMQP URI, provide it directly and omit the individual connection fields:
from swarmauri_publisher_rabbitmq import RabbitMQPublisher
publisher = RabbitMQPublisher(
uri="amqp://guest:guest@localhost:5672/",
exchange="demo_exchange",
)
publisher.publish(
channel="demo.routing.key",
payload={"message": "Hello RabbitMQ via URI!"},
)
Behavior notes
- Credentials are URL-encoded via
urllib.parse.quote_pluswhen constructing an AMQP URI from discrete fields, and a username can be supplied without a password if the broker permits it. pika.BasicPropertiesis called withdelivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE.- If RabbitMQ closes the channel or the connection drops, the publisher closes the connection, recreates it with the original URI, re-declares the exchange, and retries the publish once.
- When the publisher instance is garbage-collected it closes the open connection if it is still active.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Metadata
Release files for swarmauri_publisher_rabbitmq 0.11.0.dev1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| swarmauri_publisher_rabbitmq-0.11.0.dev1.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| swarmauri_publisher_rabbitmq-0.11.0.dev1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.2 kB
Release files / swarmauri_publisher_rabbitmq-0.11.0.dev1.tar.gz
| Download URL | swarmauri_publisher_rabbitmq-0.11.0.dev1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62ba1c5ca12da271016edd3534541d412f67f253bb22a86b0104d8095ed1a2a3
|
|
BLAKE2b-256 checksum How to use checksums |
5d566d02a4206121be5c8f40c3394342e2bc00db7d8aa48fbb56a111e085244a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_publisher_rabbitmq-0.11.0.dev1-py3-none-any.whl
| Download URL | swarmauri_publisher_rabbitmq-0.11.0.dev1-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db3426e3a5dd12921547ec0796ca5396ab4be8b8867dbd1dfa8044bc29d78872
|
|
BLAKE2b-256 checksum How to use checksums |
46f555481ea5349a2df3689c1f16f36cbb053fb39bd707436bba4fe2137099ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|