mirror of https://github.com/celery/kombu.git
Adds BrokerConnection.as_uri(). Moved from Celery to Kombu
This commit is contained in:
parent
85112484d6
commit
b3f005e3e2
|
@ -22,6 +22,12 @@ from kombu.utils.compat import OrderedDict
|
||||||
from kombu.utils.functional import wraps
|
from kombu.utils.functional import wraps
|
||||||
|
|
||||||
|
|
||||||
|
#: Connection info -> URI
|
||||||
|
URI_FORMAT = """\
|
||||||
|
%(transport)s://%(userid)s@%(hostname)s%(port)s%(virtual_host)s\
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class BrokerConnection(object):
|
class BrokerConnection(object):
|
||||||
"""A connection to the broker.
|
"""A connection to the broker.
|
||||||
|
|
||||||
|
@ -60,6 +66,8 @@ class BrokerConnection(object):
|
||||||
>>> conn.release()
|
>>> conn.release()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
URI_FORMAT = URI_FORMAT
|
||||||
|
|
||||||
port = None
|
port = None
|
||||||
virtual_host = "/"
|
virtual_host = "/"
|
||||||
connect_timeout = 5
|
connect_timeout = 5
|
||||||
|
@ -237,6 +245,16 @@ class BrokerConnection(object):
|
||||||
("transport", transport_cls),
|
("transport", transport_cls),
|
||||||
("connect_timeout", self.connect_timeout)))
|
("connect_timeout", self.connect_timeout)))
|
||||||
|
|
||||||
|
def as_uri(self):
|
||||||
|
fields = self.info()
|
||||||
|
port = fields["port"]
|
||||||
|
if port:
|
||||||
|
fields["port"] = ":%s" % (port, )
|
||||||
|
vhost = fields["virtual_host"]
|
||||||
|
if not vhost.startswith('/'):
|
||||||
|
fields["virtual_host"] = '/' + vhost
|
||||||
|
return self.URI_FORMAT % fields
|
||||||
|
|
||||||
def Pool(self, limit=None, preload=None):
|
def Pool(self, limit=None, preload=None):
|
||||||
"""Pool of connections.
|
"""Pool of connections.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue