Skip to main content

A RabbitMQ publisher implementation for Swarmauri.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_publisher_rabbitmq


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.dumps and publishes with delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE so messages survive broker restarts.
  • On pika.exceptions.AMQPConnectionError or ChannelClosedByBroker the 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 The exchange name to declare and publish to. Declared as a durable direct exchange.
uri ⚪️ Full AMQP URI. When provided, omit host/port/username/password.
host ⚪️ RabbitMQ host. Required when uri is omitted.
port ⚪️ RabbitMQ port. Supply the broker port (for example 5672); the publisher does not insert a default when constructing the URI.
username ⚪️ Username used in the URI when uri is omitted. Automatically URL-encoded.
password ⚪️ 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_plus when constructing an AMQP URI from discrete fields, and a username can be supplied without a password if the broker permits it.
  • pika.BasicProperties is called with delivery_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_publisher_rabbitmq-0.3.0.dev48.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_publisher_rabbitmq-0.3.0.dev48.tar.gz.

File metadata

  • Download URL: swarmauri_publisher_rabbitmq-0.3.0.dev48.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}

File hashes

Hashes for swarmauri_publisher_rabbitmq-0.3.0.dev48.tar.gz
Algorithm Hash digest
SHA256 fad2067b91f6f0121f54b2b66bea1f0dd3ad08d726e40fcda448b38c884961c0
MD5 ca7192542bc8bb3ef886abef2264cbb8
BLAKE2b-256 6361d3e3929615d070300e229abfb05b0f5f7ef80279cea4a5c3d2a1d1a8ba8e

See more details on using hashes here.

File details

Details for the file swarmauri_publisher_rabbitmq-0.3.0.dev48-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_publisher_rabbitmq-0.3.0.dev48-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}

File hashes

Hashes for swarmauri_publisher_rabbitmq-0.3.0.dev48-py3-none-any.whl
Algorithm Hash digest
SHA256 9724d6d88a5e558ce570bbc76bfaf0a4c8251a6d35b5626b4f84edb5a0026e32
MD5 eeba40f7a49d9456f10d36c97c372897
BLAKE2b-256 768786b2cef9d132692f69cf1fedd31ffe9601a50a6314cadb754a15827a9608

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page