Connection Parameters¶
To maintain flexibility in how you specify the connection information required for your applications to properly connect to RabbitMQ, pika implements two classes for encapsulating the information, ConnectionParameters
and URLParameters
.
ConnectionParameters¶
The classic object for specifying all of the connection parameters required to connect to RabbitMQ, ConnectionParameters
provides attributes for tweaking every possible connection option.
Example:
import pika
# Set the connection parameters to connect to rabbit-server1 on port 5672
# on the / virtual host using the username "guest" and password "guest"
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('rabbit-server1',
5672,
'/',
credentials)
-
class
pika.connection.
ConnectionParameters
(host=None, port=None, virtual_host=None, credentials=None, channel_max=None, frame_max=None, heartbeat_interval=None, ssl=None, ssl_options=None, connection_attempts=None, retry_delay=None, socket_timeout=None, locale=None, backpressure_detection=None)¶ Connection parameters object that is passed into the connection adapter upon construction.
Parameters: - host (str) – Hostname or IP Address to connect to
- port (int) – TCP port to connect to
- virtual_host (str) – RabbitMQ virtual host to use
- credentials (pika.credentials.Credentials) – auth credentials
- channel_max (int) – Maximum number of channels to allow
- frame_max (int) – The maximum byte size for an AMQP frame
- heartbeat_interval (int) – How often to send heartbeats
- ssl (bool) – Enable SSL
- ssl_options (dict) – Arguments passed to ssl.wrap_socket as
- connection_attempts (int) – Maximum number of retry attempts
- retry_delay (int|float) – Time to wait in seconds, before the next
- socket_timeout (int|float) – Use for high latency networks
- locale (str) – Set the locale value
- backpressure_detection (bool) – Toggle backpressure detection
URLParameters¶
The URLParameters
class allows you to pass in an AMQP URL when creating the object and supports the host, port, virtual host, ssl, username and password in the base URL and other options are passed in via query parameters.
Example:
import pika
# Set the connection parameters to connect to rabbit-server1 on port 5672
# on the / virtual host using the username "guest" and password "guest"
parameters = pika.URLParameters('amqp://guest:guest@rabbit-server1:5672/%2F')
-
class
pika.connection.
URLParameters
(url)¶ Connect to RabbitMQ via an AMQP URL in the format:
amqp://username:password@host:port/<virtual_host>[?query-string]
Ensure that the virtual host is URI encoded when specified. For example if you are using the default “/” virtual host, the value should be %2f.
Valid query string values are:
- backpressure_detection:
- Toggle backpressure detection, possible values are t or f
- channel_max:
- Override the default maximum channel count value
- connection_attempts:
- Specify how many times pika should try and reconnect before it gives up
- frame_max:
- Override the default maximum frame size for communication
- heartbeat_interval:
- Specify the number of seconds between heartbeat frames to ensure that the link between RabbitMQ and your application is up
- locale:
- Override the default en_US locale value
- ssl:
- Toggle SSL, possible values are t, f
- ssl_options:
- Arguments passed to
ssl.wrap_socket()
- retry_delay:
- The number of seconds to sleep before attempting to connect on connection failure.
- socket_timeout:
- Override low level socket timeout value
Parameters: url (str) – The AMQP URL to connect to