Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:18:22+00:00 2026-06-04T13:18:22+00:00

I’m using Django and Celery and I’m trying to setup routing to multiple queues.

  • 0

I’m using Django and Celery and I’m trying to setup routing to multiple queues. When I specify a task’s routing_key and exchange (either in the task decorator or using apply_async()), the task isn’t added to the broker (which is Kombu connecting to my MySQL database).

If I specify the queue name in the task decorator (which will mean the routing key is ignored), the task works fine. It appears to be a problem with the routing/exchange setup.

Any idea what the problem could be?

Here’s the setup:

settings.py

INSTALLED_APPS = (
    ...
    'kombu.transport.django',
    'djcelery',
)
BROKER_BACKEND = 'django'
CELERY_DEFAULT_QUEUE = 'default'
CELERY_DEFAULT_EXCHANGE = "tasks"
CELERY_DEFAULT_EXCHANGE_TYPE = "topic"
CELERY_DEFAULT_ROUTING_KEY = "task.default"
CELERY_QUEUES = {
    'default': {
        'binding_key':'task.#',
    },
    'i_tasks': {
        'binding_key':'important_task.#',
    },
}

tasks.py

from celery.task import task

@task(routing_key='important_task.update')
def my_important_task():
    try:
        ...
    except Exception as exc:
        my_important_task.retry(exc=exc)

Initiate task:

from tasks import my_important_task
my_important_task.delay()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:18:24+00:00Added an answer on June 4, 2026 at 1:18 pm

    You are using the Django ORM as a broker, which means declarations are only stored in memory
    (see the, inarguably hard to find, transport comparison table at http://readthedocs.org/docs/kombu/en/latest/introduction.html#transport-comparison)

    So when you apply this task with routing_key important_task.update it will not be able
    to route it, because it hasn’t declared the queue yet.

    It will work if you do this:

    @task(queue="i_tasks", routing_key="important_tasks.update")
    def important_task():
        print("IMPORTANT")
    

    But it would be much simpler for you to use the automatic routing feature,
    since there’s nothing here that shows you need to use a ‘topic’ exchange,
    to use automatic routing simply remove the settings:

    • CELERY_DEFAULT_QUEUE,
    • CELERY_DEFAULT_EXCHANGE,
    • CELERY_DEFAULT_EXCHANGE_TYPE
    • CELERY_DEFAULT_ROUTING_KEY
    • CELERY_QUEUES

    And declare your task like this:

    @task(queue="important")
    def important_task():
        return "IMPORTANT"
    

    and then to start a worker consuming from that queue:

    $ python manage.py celeryd -l info -Q important
    

    or to consume from both the default (celery) queue and the important queue:

    $ python manage.py celeryd -l info -Q celery,important
    

    Another good practice is to not hardcode the queue names into the
    task and use CELERY_ROUTES instead:

    @task
    def important_task():
        return "DEFAULT"
    

    then in your settings:

    CELERY_ROUTES = {"myapp.tasks.important_task": {"queue": "important"}}
    

    If you still insist on using topic exchanges then you could
    add this router to automatically declare all queues the first time
    a task is sent:

    class PredeclareRouter(object):
        setup = False
    
        def route_for_task(self, *args, **kwargs):
            if self.setup:
                return
            self.setup = True
            from celery import current_app, VERSION as celery_version
            # will not connect anywhere when using the Django transport
            # because declarations happen in memory.
            with current_app.broker_connection() as conn:
                queues = current_app.amqp.queues
                channel = conn.default_channel
                if celery_version >= (2, 6):
                    for queue in queues.itervalues():
                        queue(channel).declare()
                else:
                    from kombu.common import entry_to_queue
                    for name, opts in queues.iteritems():
                        entry_to_queue(name, **opts)(channel).declare()
    CELERY_ROUTES = (PredeclareRouter(), )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.