Exemplo n.º 1
0
    def expand_destination(self, route):
        # Route can be a queue name: convenient for direct exchanges.
        if isinstance(route, basestring):
            queue, route = route, {}
        else:
            # can use defaults from configured queue, but override specific
            # things (like the routing_key): great for topic exchanges.
            queue = route.pop("queue", None)

        if queue:  # expand config from configured queue.
            try:
                dest = dict(self.queues[queue])
            except KeyError:
                if not self.create_missing:
                    raise QueueNotFound(
                        "Queue %r is not defined in CELERY_QUEUES" % queue)
                for key in "exchange", "routing_key":
                    if route.get(key) is None:
                        route[key] = queue
                dest = dict(self.app.amqp.queues.add(queue, **route))
            # needs to be declared by publisher
            dest["queue"] = queue
            # routing_key and binding_key are synonyms.
            dest.setdefault("routing_key", dest.get("binding_key"))
            return lpmerge(dest, route)
        return route
Exemplo n.º 2
0
    def expand_destination(self, route):
        # Route can be a queue name: convenient for direct exchanges.
        if isinstance(route, string_t):
            queue, route = route, {}
        else:
            # can use defaults from configured queue, but override specific
            # things (like the routing_key): great for topic exchanges.
            queue = route.pop('queue', None)

        if queue:
            try:
                Q = self.queues[queue]  # noqa
            except KeyError:
                raise QueueNotFound(
                    'Queue {0!r} missing from CELERY_QUEUES'.format(queue))
            # needs to be declared by publisher
            route['queue'] = Q
        return route
Exemplo n.º 3
0
    def expand_destination(self, route):
        # Route can be a queue name: convenient for direct exchanges.
        if isinstance(route, string_t):
            queue, route = route, {}
        else:
            # can use defaults from configured queue, but override specific
            # things (like the routing_key): great for topic exchanges.
            queue = route.pop('queue', None)

        if queue:
            if isinstance(queue, Queue):
                route['queue'] = queue
            else:
                try:
                    route['queue'] = self.queues[queue]
                except KeyError:
                    raise QueueNotFound(
                        'Queue {0!r} missing from task_queues'.format(queue))
        return route
Exemplo n.º 4
0
    def expand_destination(self, route):
        # Route can be a queue name: convenient for direct exchanges.
        if isinstance(route, basestring):
            queue, route = route, {}
        else:
            # can use defaults from configured queue, but override specific
            # things (like the routing_key): great for topic exchanges.
            queue = route.pop('queue', None)

        if queue:
            try:
                Q = self.queues[queue]  # noqa
            except KeyError:
                if not self.create_missing:
                    raise QueueNotFound(
                        'Queue %r is not defined in CELERY_QUEUES' % queue)
                for key in 'exchange', 'routing_key':
                    if route.get(key) is None:
                        route[key] = queue
                Q = self.app.amqp.queues.add(queue, **route)
            # needs to be declared by publisher
            route['queue'] = Q
        return route
Exemplo n.º 5
0
    def expand_destination(self, route):
        # The route can simply be a queue name,
        # this is convenient for direct exchanges.
        if isinstance(route, basestring):
            queue, route = route, {}
        else:
            # For topic exchanges you can use the defaults from a queue
            # definition, and override e.g. just the routing_key.
            queue = route.pop("queue", None)

        if queue:
            try:
                dest = dict(self.queues[queue])
            except KeyError:
                if self.create_missing:
                    dest = self.add_queue(queue)
                else:
                    raise QueueNotFound(
                        "Queue '%s' is not defined in CELERY_QUEUES" % queue)
            dest.setdefault("routing_key", dest.get("binding_key"))
            return merge(dest, route)

        return route
Exemplo n.º 6
0
    def expand_destination(self, route):
        # Route can be a queue name: convenient for direct exchanges.
        if isinstance(route, string_t):
            queue, route = route, {}
        else:
            # can use defaults from configured queue, but override specific
            # things (like the routing_key): great for topic exchanges.
            queue = route.pop('queue', None)

        if queue:  # expand config from configured queue.
            try:
                dest = self.queues[queue].as_dict()
            except KeyError:
                if not self.create_missing:
                    raise QueueNotFound(
                        'Queue {0!r} missing from CELERY_QUEUES'.format(queue))
                for key in 'exchange', 'routing_key':
                    if route.get(key) is None:
                        route[key] = queue
                dest = self.app.amqp.queues.add(queue, **route).as_dict()
            # needs to be declared by publisher
            dest['queue'] = queue
            return lpmerge(dest, route)
        return route