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=<class 'pika.connection.ConnectionParameters._DEFAULT'>, port=<class 'pika.connection.ConnectionParameters._DEFAULT'>, virtual_host=<class 'pika.connection.ConnectionParameters._DEFAULT'>, credentials=<class 'pika.connection.ConnectionParameters._DEFAULT'>, channel_max=<class 'pika.connection.ConnectionParameters._DEFAULT'>, frame_max=<class 'pika.connection.ConnectionParameters._DEFAULT'>, heartbeat=<class 'pika.connection.ConnectionParameters._DEFAULT'>, ssl_options=<class 'pika.connection.ConnectionParameters._DEFAULT'>, connection_attempts=<class 'pika.connection.ConnectionParameters._DEFAULT'>, retry_delay=<class 'pika.connection.ConnectionParameters._DEFAULT'>, socket_timeout=<class 'pika.connection.ConnectionParameters._DEFAULT'>, stack_timeout=<class 'pika.connection.ConnectionParameters._DEFAULT'>, locale=<class 'pika.connection.ConnectionParameters._DEFAULT'>, blocked_connection_timeout=<class 'pika.connection.ConnectionParameters._DEFAULT'>, client_properties=<class 'pika.connection.ConnectionParameters._DEFAULT'>, tcp_options=<class 'pika.connection.ConnectionParameters._DEFAULT'>, **kwargs)[source]¶
Connection parameters object that is passed into the connection adapter upon construction.
- property blocked_connection_timeout¶
- property channel_max¶
- Returns
max preferred number of channels. Defaults to DEFAULT_CHANNEL_MAX.
- Return type
- property client_properties¶
- property connection_attempts¶
- Returns
number of socket connection attempts. Defaults to DEFAULT_CONNECTION_ATTEMPTS. See also retry_delay.
- Return type
- property credentials¶
- Return type
one of the classes from pika.credentials.VALID_TYPES. Defaults to DEFAULT_CREDENTIALS.
- property frame_max¶
- Returns
desired maximum AMQP frame size to use. Defaults to DEFAULT_FRAME_MAX.
- Return type
- property heartbeat¶
- property locale¶
- Returns
locale value to pass to broker; e.g., ‘en_US’. Defaults to DEFAULT_LOCALE.
- Return type
- property retry_delay¶
- Returns
interval between socket connection attempts; see also connection_attempts. Defaults to DEFAULT_RETRY_DELAY.
- Return type
- property socket_timeout¶
- property stack_timeout¶
- Returns
full protocol stack TCP/[SSL]/AMQP bring-up timeout in seconds. Defaults to DEFAULT_STACK_TIMEOUT. The value None disables this timeout.
- Return type
- property ssl_options¶
- Returns
None for plaintext or pika.SSLOptions instance for SSL/TLS.
- Return type
`pika.SSLOptions`|None
- property port¶
- Returns
port number of broker’s listening socket. Defaults to DEFAULT_PORT.
- Return type
- property virtual_host¶
- Returns
rabbitmq virtual host name. Defaults to DEFAULT_VIRTUAL_HOST.
- Return type
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)[source]¶
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.
See Parameters for default values.
Valid query string values are:
- channel_max:
Override the default maximum channel count value
- client_properties:
dict of client properties used to override the fields in the default client properties reported to RabbitMQ via Connection.StartOk method
- 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:
Desired connection heartbeat timeout for negotiation. If not present the broker’s value is accepted. 0 turns heartbeat off.
- locale:
Override the default en_US locale value
- ssl_options:
None for plaintext; for SSL: dict of public ssl context-related arguments that may be passed to
ssl.SSLSocket()
as kwargs, except sock, server_side,`do_handshake_on_connect`, family, type, proto, fileno.
- retry_delay:
The number of seconds to sleep before attempting to connect on connection failure.
- socket_timeout:
Socket connect timeout value in seconds (float or int)
- stack_timeout:
Positive full protocol stack (TCP/[SSL]/AMQP) bring-up timeout in seconds. It’s recommended to set this value higher than socket_timeout.
- blocked_connection_timeout:
Set the timeout, in seconds, that the connection may remain blocked (triggered by Connection.Blocked from broker); if the timeout expires before connection becomes unblocked, the connection will be torn down, triggering the connection’s on_close_callback
- tcp_options:
Set the tcp options for the underlying socket.
- Parameters
url (str) – The AMQP URL to connect to
- property ssl_options¶
- Returns
None for plaintext or pika.SSLOptions instance for SSL/TLS.
- Return type
`pika.SSLOptions`|None
- property port¶
- Returns
port number of broker’s listening socket. Defaults to DEFAULT_PORT.
- Return type
- property credentials¶
- Return type
one of the classes from pika.credentials.VALID_TYPES. Defaults to DEFAULT_CREDENTIALS.
- property virtual_host¶
- Returns
rabbitmq virtual host name. Defaults to DEFAULT_VIRTUAL_HOST.
- Return type
- property blocked_connection_timeout¶
- property channel_max¶
- Returns
max preferred number of channels. Defaults to DEFAULT_CHANNEL_MAX.
- Return type
- property client_properties¶
- property connection_attempts¶
- Returns
number of socket connection attempts. Defaults to DEFAULT_CONNECTION_ATTEMPTS. See also retry_delay.
- Return type
- property frame_max¶
- Returns
desired maximum AMQP frame size to use. Defaults to DEFAULT_FRAME_MAX.
- Return type
- property heartbeat¶
- property locale¶
- Returns
locale value to pass to broker; e.g., ‘en_US’. Defaults to DEFAULT_LOCALE.
- Return type
- property retry_delay¶
- Returns
interval between socket connection attempts; see also connection_attempts. Defaults to DEFAULT_RETRY_DELAY.
- Return type
- property socket_timeout¶
- property stack_timeout¶
- Returns
full protocol stack TCP/[SSL]/AMQP bring-up timeout in seconds. Defaults to DEFAULT_STACK_TIMEOUT. The value None disables this timeout.
- Return type