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.
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)
Connection parameters object that is passed into the connection adapter upon construction.
Parameters: |
|
---|
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')
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 |
---|