Connection

class amqpstorm.Connection[source]

RabbitMQ Connection.

e.g.

import amqpstorm
connection = amqpstorm.Connection('localhost', 'guest', 'guest')

Using a SSL Context:

import ssl
import amqpstorm
ssl_options = {
    'context': ssl.create_default_context(cafile='ca_certificate.pem'),
    'server_hostname': 'rmq.eandersson.net',
    'check_hostname': True,
    'verify_mode': ssl.CERT_REQUIRED,
}
connection = amqpstorm.Connection(
    'rmq.eandersson.net', 'guest', 'guest', port=5671,
    ssl=True, ssl_options=ssl_options
)
Parameters:
  • hostname (str) – Hostname

  • username (str) – Username

  • password (str) – Password

  • port (int) – Server port

  • virtual_host (str) – Virtual host

  • heartbeat (int) – RabbitMQ Heartbeat timeout

  • timeout (int,float) – Socket timeout

  • ssl (bool) – Enable SSL

  • ssl_options (dict) – SSL kwargs

  • client_properties (dict) – None or dict of client properties

  • poller (str) – Either “select” or “poll”. If you encounter file descriptor errors, consider switching to “poll”.

  • locale (str) – Locale used during connection negotiation. Defaults to “en_US”.

  • lazy (bool) – Lazy initialize the connection

Raises:

AMQPConnectionError – Raises if the connection encountered an error.

__init__(hostname: str, username: str, password: str, port: int = 5672, **kwargs: Any) None[source]
property channels: dict[int, Channel]

Returns a dictionary of the Channels currently available.

Return type:

dict

property fileno: int | None

Returns the Socket File number.

Return type:

integer,None

property is_blocked: bool

Is the connection currently being blocked from publishing by the remote server.

Return type:

bool

property max_allowed_channels: int

Returns the maximum allowed channels for the connection.

Return type:

int

property max_frame_size: int

Returns the maximum allowed frame size for the connection.

Return type:

int

property server_properties: dict[str, Any]

Returns the RabbitMQ Server Properties.

Return type:

dict

property socket: _socket.socket | None

Returns an instance of the Socket used by the Connection.

Return type:

socket

channel(rpc_timeout: float = 60, lazy: bool = False) Channel[source]

Open a Channel.

Parameters:

rpc_timeout (int) – Timeout before we give up waiting for an RPC response from the server.

Raises:
Return type:

Channel

check_for_errors() None[source]

Check Connection for errors.

Raises:

AMQPConnectionError – Raises if the connection encountered an error.

Returns:

close() None[source]

Close the Connection.

Raises:

AMQPConnectionError – Raises if the connection encountered an error.

Returns:

open() None[source]

Open Connection.

Raises:

AMQPConnectionError – Raises if the connection encountered an error.

classmethod __new__(*args, **kwargs)

UriConnection

class amqpstorm.UriConnection[source]

RabbitMQ Connection that takes a Uri string.

e.g.

import amqpstorm
connection = amqpstorm.UriConnection(
    'amqp://guest:guest@localhost:5672/%2F?heartbeat=60'
)

Using a SSL Context:

import ssl
import amqpstorm
ssl_options = {
    'context': ssl.create_default_context(cafile='ca_certificate.pem'),
    'server_hostname': 'rmq.eandersson.net'
}
connection = amqpstorm.UriConnection(
    'amqps://guest:guest@rmq.eandersson.net:5671/%2F?heartbeat=60',
    ssl_options=ssl_options
)
Parameters:
  • uri (str) – AMQP Connection string

  • ssl_options (dict) – SSL kwargs

  • client_properties (dict) – None or dict of client properties

  • lazy (bool) – Lazy initialize the connection

Raises:
__init__(uri: str, ssl_options: dict[str, Any] | None = None, client_properties: dict[str, Any] | None = None, lazy: bool = False) None[source]