<p>我对AMQP的理解是,消息只有以下组件:</p>
<ol>
<li>消息正文</li>
<li>路由密钥</li>
<li>交易所</li>
</ol>
<p>队列附加到交换机。消息不能有任何队列知识。它们只是发送到一个exchange,然后根据exchange类型和路由密钥,将消息路由到一个或多个队列。</p>
<p>在芹菜中,建议通过<code>CELERY_ROUTES</code>设置路由任务。从文档中,<code>CELERY_ROUTES</code>是。。。</p>
<blockquote>
<p>A list of routers, or a single router used to route tasks to queues.
<a href="http://celery.readthedocs.org/en/latest/configuration.html#message-routing" rel="noreferrer">http://celery.readthedocs.org/en/latest/configuration.html#message-routing</a></p>
</blockquote>
<p>包括一个例子。。。</p>
<blockquote>
<p>To route a task to the feed_tasks queue, you can add an entry in the
<code>CELERY_ROUTES</code> setting:</p>
<pre><code>CELERY_ROUTES = {
'feeds.tasks.import_feed': {
'queue': 'feed_tasks',
'routing_key': 'feed.import',
},
}
</code></pre>
</blockquote>
<p>但请稍等——根据AMQP的说法,消息只有一个路由密钥!“排队”在那里干什么?</p>
<p>此外,还有一个默认队列的概念。如果调用的任务不是由<code>CELERY_ROUTES</code>捕获的,则返回到<code>CELERY_DEFAULT_QUEUE</code>。但是,在AMQP中,消息不知道队列。那不应该是默认的路由密钥吗?</p>