amqp assertQueue bork a connection 含义

amqp assertQueue bork a connection meaning

在 amqp 的 assertQueue API 文档中,它指出:

断言队列存在。给定相同的参数,此操作是幂等的;但是,如果队列已经存在但具有不同的属性,它将使通道阻塞(参数字段中提供的值可能会或可能不会用于阻塞目的;检查 borker 的,我的意思是经纪人的文档)。

http://www.squaremobius.net/amqp.node/channel_api.html#channel_assertQueue

我问的是bork(ing)频道是什么意思。我试过 google 但找不到任何相关内容。

RabbitMQ 团队监控 this mailing list 并且有时只在 Whosebug 上回答问题。

话虽如此,您是否尝试调用 assertQueue 两次,第二次使用不同的属性?你会很快回答你自己的问题。

我使用 this code 创建了这个测试程序:

#!/usr/bin/env node

var amqp = require('amqplib');

amqp.connect('amqp://localhost').then(function(conn) {
  return conn.createChannel().then(function(ch) {
    var q = 'hello';
    var ok0 = ch.assertQueue(q, {durable: false});
    return ok0.then(function(_qok) {
        var ok1 = ch.assertQueue(q, {durable: true});
        return ok1.then(function(got) {
            console.log(" [x] got '%s'", got);
            return ch.close();
        });
    });
  }).finally(function() { conn.close(); });
}).catch(console.warn);

然后,启动 RabbitMQ 和 运行 您的测试代码。您应该看到这样的输出:

$ node examples/tutorials/assert-borked.js
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'true' but current is 'false'"
    at Channel.C.accept

Bork:英文意思是阻碍某事。

根据问题中的文档,它说

however, it will bork the channel if the queue already exists but has different properties

这意味着如果您尝试创建一个与已经存在的通道具有相同属性的通道,则不会发生任何事情,因为它是 idempotent(意味着重复相同的操作而没有不同的结果,例如REST API GET 请求获取 id 为 123 的数据,除非更新,否则每次都会 return 相同的数据,这是一个非常有趣的视频,解释了无能的概念),但是如果您尝试使用名称相同但属性不同,通道创建应为“borked”,即阻塞。

在下面的代码中,我们再次创建频道,

 var ok0 = ch.assertQueue(q, {durable: false});// creating the first time
 var ok1 = ch.assertQueue(q, {durable: true});// creating the second time again with different durable property value

抛出一个错误

"PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'true' but current is 'false'"

这意味着您正在尝试制作具有不同属性的相同频道,即耐用 属性 与现有频道不同,因此它已被屏蔽。

[2]:@Like Bakken 的回答