Skip to content

Commit

Permalink
Resolve amqp alias at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Aug 23, 2012
1 parent f82ac71 commit 31d7869
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
5 changes: 3 additions & 2 deletions kombu/connection.py
Expand Up @@ -24,7 +24,7 @@
# (Issue #112)
from kombu import exceptions
from .log import get_logger
from .transport import AMQP_ALIAS, get_transport_cls
from .transport import get_transport_cls, supports_librabbitmq
from .utils import cached_property, retry_over_time
from .utils.compat import OrderedDict, LifoQueue as _LifoQueue
from .utils.url import parse_url
Expand Down Expand Up @@ -133,6 +133,8 @@ def __init__(self, hostname='localhost', userid=None,

def _init_params(self, hostname, userid, password, virtual_host, port,
insist, ssl, transport, connect_timeout, login_method, heartbeat):
if transport == 'amqp' and supports_librabbitmq():
transport = 'librabbitmq'
self.hostname = hostname
self.userid = userid
self.password = password
Expand Down Expand Up @@ -403,7 +405,6 @@ def clone(self, **kwargs):

def _info(self):
transport_cls = self.transport_cls or 'amqp'
transport_cls = {AMQP_ALIAS: 'amqp'}.get(transport_cls, transport_cls)
D = self.transport.default_connection_params
hostname = self.hostname or D.get('hostname')
if self.uri_prefix:
Expand Down
22 changes: 9 additions & 13 deletions kombu/transport/__init__.py
Expand Up @@ -12,19 +12,17 @@

import sys

from kombu.syn import detect_environment
from kombu.syn import _detect_environment

DEFAULT_TRANSPORT = 'amqp'

AMQP_TRANSPORT = 'kombu.transport.amqplib.Transport'
AMQP_ALIAS = 'librabbitmq'
if detect_environment() == 'default':
try:
import librabbitmq # noqa
AMQP_TRANSPORT = 'kombu.transport.librabbitmq.Transport' # noqa
AMQP_ALIAS = 'amqp' # noqa
except ImportError:
pass
def supports_librabbitmq():
if _detect_environment() == 'default':
try:
import librabbitmq # noqa
return True
except ImportError:
pass
return False


def _ghettoq(name, new, alias=None):
Expand All @@ -48,7 +46,6 @@ def __inner():


TRANSPORT_ALIASES = {
'amqp': AMQP_TRANSPORT,

This comment has been minimized.

Copy link
@gabrtv

gabrtv Aug 24, 2012

This change seemed to break the following calling code:

celery = Celery('mymodule', broker='amqp://guest@localhost//', backend='amqp')

Full stack trace can be found at: http://stackoverflow.com/questions/12115692/celery-error-no-such-transport-amqp/12115697#12115697

Downgrading to Celery 3.0.6 and Kombu 2.4.0 resolved the issue in the meantime. Thoughts?

'pyamqp': 'kombu.transport.pyamqp.Transport',
'amqplib': 'kombu.transport.amqplib.Transport',
'librabbitmq': 'kombu.transport.librabbitmq.Transport',
Expand Down Expand Up @@ -106,7 +103,6 @@ def get_transport_cls(transport=None):
the alias table will be consulted.
"""
transport = transport or DEFAULT_TRANSPORT
if transport not in _transport_cache:
_transport_cache[transport] = _get_transport_cls(transport)
return _transport_cache[transport]

4 comments on commit 31d7869

@ask
Copy link
Contributor Author

@ask ask commented on 31d7869 Aug 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrtv I don't get any errors when I execute that line?

@gabrtv
Copy link

@gabrtv gabrtv commented on 31d7869 Aug 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ask

File "/home/buildslave/venv/local/lib/python2.7/site-packages/kombu/transport/__init__.py", line 87, in resolve_transport
    raise KeyError('No such transport: %s' % (transport, ))
KeyError: 'No such transport: amqp'

..shows the exception being raised on line 87, which matches 2.4.0:
https://github.com/celery/kombu/blob/v2.4.0/kombu/transport/__init__.py#L87

..in 2.4.2 it's raised on line 84:
https://github.com/celery/kombu/blob/v2.4.2/kombu/transport/__init__.py#L84

I'm going to chalk this one up to a failed pip install -U -r requirements.txt. Thanks...

@ask
Copy link
Contributor Author

@ask ask commented on 31d7869 Aug 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks, yeah that seems to happen from time to time :/

@rodbegbie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing a related(?) issue. Filed as issue #154

Please sign in to comment.