My understanding of AMQP is that messages only have the following components:
- The message body
- The routing key
- The exchange
Queues are attached to exchanges. Messages can't have any knowledge of queues. They just post to an exchange, and then based on the exchange type and routing key, the messages are routed to one or more queues.
In Celery, the recommended way of routing tasks is through the CELERY_ROUTES
setting. From the docs, CELERY_ROUTES
is...
A list of routers, or a single router used to route tasks to queues. http://celery.readthedocs.org/en/latest/configuration.html#message-routing
And it includes an example...
To route a task to the feed_tasks queue, you can add an entry in the
CELERY_ROUTES
setting:CELERY_ROUTES = { 'feeds.tasks.import_feed': { 'queue': 'feed_tasks', 'routing_key': 'feed.import', }, }
But wait a minute -- According to AMQP, messages only come with a routing key! What the heck is the "queue" doing there?
Furthermore, there's this notion of a default queue. If you invoke a task which isn't caught by CELERY_ROUTES
, it falls back to CELERY_DEFAULT_QUEUE
. But again -- in AMQP, messages don't know about queues. Shouldn't that be the default routing key instead?