8
from carrot.utils import rpartition
10
DEFAULT_BACKEND = "carrot.backends.pyamqplib.Backend"
13
"amqp": "carrot.backends.pyamqplib.Backend",
14
"amqplib": "carrot.backends.pyamqplib.Backend",
15
"stomp": "carrot.backends.pystomp.Backend",
16
"stompy": "carrot.backends.pystomp.Backend",
17
"memory": "carrot.backends.queue.Backend",
18
"mem": "carrot.backends.queue.Backend",
19
"pika": "carrot.backends.pikachu.AsyncoreBackend",
20
"pikachu": "carrot.backends.pikachu.AsyncoreBackend",
21
"syncpika": "carrot.backends.pikachu.SyncBackend",
27
def resolve_backend(backend=None):
28
backend = BACKEND_ALIASES.get(backend, backend)
29
backend_module_name, _, backend_cls_name = rpartition(backend, ".")
30
return backend_module_name, backend_cls_name
33
def _get_backend_cls(backend=None):
34
backend_module_name, backend_cls_name = resolve_backend(backend)
35
__import__(backend_module_name)
36
backend_module = sys.modules[backend_module_name]
37
return getattr(backend_module, backend_cls_name)
40
def get_backend_cls(backend=None):
41
"""Get backend class by name.
43
The backend string is the full path to a backend class, e.g.::
45
"carrot.backends.pyamqplib.Backend"
47
If the name does not include "``.``" (is not fully qualified),
48
the alias table will be consulted.
51
backend = backend or DEFAULT_BACKEND
52
if backend not in _backend_cache:
53
_backend_cache[backend] = _get_backend_cls(backend)
54
return _backend_cache[backend]