每次我将AMQP队列绑定到交换机时,它自动似乎绑定到“默认”直接交换.
这是使用rabbitMQ服务器和node.js的代码:
var amqp = require('amqp');
var connection = amqp.createConnection({host:'localhost'});
connection.on('ready', function(){
var q = connection.queue('test_queue_name');
var exc = connection.exchange('test_exchange', { autoDelete:true });
q.bind('test_exchange', 'test.key');
});
这是使用“rabbitmqctl list_bindings”命令时的控制台输出:
Listing bindings ...
exchange test_queue_name queue test_queue_name []
test_exchange exchange test_queue_name queue test.key []
...done.
解决方法:
RabbitMQ使用与队列名称相同的路由密钥自动将每个队列绑定到默认交换.
从docs
The default exchange is a direct exchange with no name (empty string) pre-declared by the broker. It has one special property that makes it very useful for simple applications: every queue that is created is automatically bound to it with a routing key which is the same as the queue name.
我很确定这是AMQP规范的一部分.