<p>确实,在芹菜上,当您进入队列时会有一点混乱,您必须记住的一点是,queue参数指的是芹菜Kombu队列对象,而不是直接指向AMQP队列,您可以通过阅读本文<a href="http://celery.readthedocs.org/en/latest/userguide/routing.html#how-the-queues-are-defined" rel="noreferrer">extract from the docs</a>来理解这一点。
当然,芹菜创建队列并用同一个名称交换的事实是队列参数使用混乱的根源。
在文档中,您可以阅读以下段落:</p>
<blockquote>
<p>If you have another queue but on another exchange you want to add, just specify a custom exchange and exchange type:</p>
<pre><code>CELERY_QUEUES = (
Queue('feed_tasks', routing_key='feed.#'),
Queue('regular_tasks', routing_key='task.#'),
Queue('image_tasks', exchange=Exchange('mediatasks', type='direct'),
routing_key='image.compress'),
)
</code></pre>
</blockquote>
<p>这样就可以在同一个交换上绑定两个不同的队列。
在仅使用exchange和密钥路由任务之后,可以使用Routers类</p>
<pre><code>class MyRouter(object):
def route_for_task(self, task, args=None, kwargs=None):
if task == 'myapp.tasks.compress_video':
return {'exchange': 'video',
'exchange_type': 'topic',
'routing_key': 'video.compress'}
return None
</code></pre>
<p>更多<a href="http://celery.readthedocs.org/en/latest/userguide/routing.html#routers" rel="noreferrer">http://celery.readthedocs.org/en/latest/userguide/routing.html#routers</a></p>