AMQPStorm

2.11.1 · active · verified Sun Apr 12

AMQPStorm is a thread-safe Python client library for RabbitMQ, offering comprehensive features for both messaging and RabbitMQ management. Currently at version 2.11.1, the library maintains an active release cadence with regular updates and improvements, ensuring stability and compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to RabbitMQ, open a channel, declare a queue, and publish a basic message using AMQPStorm. It uses environment variables for connection details and context managers for robust resource management.

import amqpstorm
import os

RABBITMQ_HOST = os.environ.get('RABBITMQ_HOST', 'localhost')
RABBITMQ_USER = os.environ.get('RABBITMQ_USER', 'guest')
RABBITMQ_PASS = os.environ.get('RABBITMQ_PASS', 'guest')

try:
    # Establish a connection using a context manager for proper resource handling
    with amqpstorm.Connection(RABBITMQ_HOST, RABBITMQ_USER, RABBITMQ_PASS) as connection:
        # Open a channel using a context manager
        with connection.channel() as channel:
            # Declare a queue (idempotent operation)
            channel.queue.declare('my_queue')

            # Publish a simple message to 'my_queue'
            channel.basic.publish(body='Hello, RabbitMQ!', routing_key='my_queue')
            print(" [x] Sent 'Hello, RabbitMQ!'")
except amqpstorm.AMQPConnectionError as e:
    print(f"Error connecting to RabbitMQ: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →