Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion amqpy/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
from __future__ import absolute_import, division, print_function

from future.moves.urllib.parse import urlparse, unquote

__metaclass__ = type
import logging
import socket
Expand Down Expand Up @@ -55,7 +57,13 @@ def __init__(self, host='localhost', port=5672, ssl=None, connect_timeout=None,
If you are using SSL, make sure the correct port number is specified (usually 5671), as the
default of 5672 is for non-SSL connections.

:param str host: host
You can define an AMQP connection string as the host, this will be used to set
the `host`, `port`, `userid`, `password` and `virtual_host`. The connection string follows
this format:

`amqp://[userid:password@]host[:port][/virtual_host]`

:param str host: host or amqp connection string
:param int port: port
:param ssl: dict of SSL options passed to :func:`ssl.wrap_socket()`, None to disable SSL
:param float connect_timeout: connect timeout
Expand Down Expand Up @@ -111,6 +119,15 @@ def __init__(self, host='localhost', port=5672, ssl=None, connect_timeout=None,
self._heartbeat_final = 0 # final heartbeat interval after negotiation
self._heartbeat_server = None

# detect amqp connection string
if host.startswith('amqp://'):
parts = urlparse("http://" + host[7:])
host = unquote(parts.hostname or '') or None
port = parts.port or 5672
userid = unquote(parts.username or '') or 'guest'
password = unquote(parts.password or '') or 'guest'
virtual_host = unquote(parts.path[1:] or '/')

# save connection parameters
self._host = host
self._port = port
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def long_description():
packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
package_data=package_data,
setup_requires=['six>=1.0'],
install_requires=['six>=1.0'],
install_requires=[
'six>=1.0',
'future>=0.16.0',
],
tests_require=['pytest>=2.6'],
classifiers=classifiers,
keywords=keywords
Expand Down