node.js - 使用 AMQP、rhea 和 Node 从 Azure 服务总线队列查看消息时获取 "amqp:internal-error"

标签 node.js azure amqp azureservicebus azure-servicebus-queues

几天前我问了同样的问题:Unable to "Peek" messages from an Azure Service Bus Queue using AMQP and Node 。我再次问同样的问题,但有一些差异(因此,请不要将此问题标记为与其他问题重复):

  • 在上一个问题中,我使用的是 nodeamqp10 库,但是根据该库的 Github 页面上的一些评论,我最终使用了 rhea而不是 nodeamqp10 库。
  • 在 Azure 服务总线团队的帮助下,我取得了一些进展,现在我从 Azure 服务总线返回了一个错误,这告诉我我走在正确的轨道上。

这是我正在使用的新代码:

var client = require('rhea');
const keyName = 'MyCustomPolicy';
const sasKey = 'SAS Key'
const serviceBusHost = 'account.servicebus.windows.net';
const queueName = '003';

client.on('connection_open', (context) => {
  context.connection.open_sender({
    target: { address: `${queueName}/$management` }
  });
});

client.once('sendable', (context) => {
  console.log('messages can be sent now....');
  var receiver = context.connection.open_receiver({
    source: { address: `${queueName}/$management` },
    autoaccept: false,
    target: { address: 'receiver-link' }
  });

  receiver.once('receiver_open', (context) => {
    console.log('receiver is now open....');
  });

  receiver.once('message', (context) => {
    console.log('message received by receiver....');
    console.log(context.message);
  });

  var messageBody = {
    'from-sequence-number': 1,
    'message-count': 5
  };

  const msg = {
    application_properties: {
      operation: 'com.microsoft:peek-message'
    },
    body: client.types.wrap_map(messageBody),
    reply_to: 'receiver-link'
  };
  context.sender.send(msg);
  console.log('message sent....');
});

client.connect({
  transport: 'tls',
  host: serviceBusHost,
  hostname: serviceBusHost,
  username: keyName,
  password: sasKey,
  port: 5671,
  reconnect_limit: 10
});

现在,当我运行此代码时,我从 Azure 服务总线返回 500 错误:

{
  "application_properties":
  {
    "statusCode":500,
    "errorCondition":"amqp:internal-error",
    "statusDescription":"The service was unable to process the request; please retry the operation. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101 Reference:ab667ed6-1565-4728-97b7-6ae4a33468b9, TrackingId:538f93a1-2c07-4bc0-bf41-dc00d7ae963c_B13, SystemTracker:account-name:Queue:003, Timestamp:8/2/2018 7:43:52 AM",
    "com.microsoft:tracking-id":"538f93a1-2c07-4bc0-bf41-dc00d7ae963c_B13"
  }
}

我什至检查了错误消息中包含的链接 ( http://go.microsoft.com/fwlink/?LinkId=761101 ),但该链接上没有提及 amqp 相关错误。

与上一个问题一样,如果我使用地址作为队列名称而不是queue-name/$management,我能够获取消息,但消息被锁定并且传递计数因为消息正在增加。此外,它返回队列中的所有消息,而不是我请求的 5 条消息。

我不确定我做错了什么。有人可以帮忙吗?

最佳答案

在Azure服务总线团队的帮助下,我找到了这个问题的解决方案(事实上,他们给了我这个解决方案)。本质上 messageBody 的元素应该使用 AMQP 类型正确编码。

以下代码有效:

  var messageBody = {
    'from-sequence-number': client.types.wrap_long(1),
    'message-count': client.types.wrap_int(5)
  };

  const msg = {
    application_properties: {
      operation: 'com.microsoft:peek-message'
    },
    body: messageBody,
    reply_to: 'receiver-link'
  };

关于node.js - 使用 AMQP、rhea 和 Node 从 Azure 服务总线队列查看消息时获取 "amqp:internal-error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51831383/

相关文章:

mule - 当通过 HTTP 请求触发时,无法使用 Mule Requester 使用 AMQP 消息

eclipse - 如何从 Eclipse 调试正在运行的 node.js 应用程序?

node.js - 在命名空间内找不到名称

azure - 当有人尝试通过 DNS 名称访问 Azure 虚拟机时,是否可以启动它?

powershell - 如何将 AAD 组设置为 AAD 应用程序的所有者?

java - 如何将视频直播发送到 azure 云?

Node.js路径错误问题

node.js - 如何安装 sequelize.js 二进制文件?

没有 amqp 服务器的 django-celery (rabbitmq)

node.js - Node.js 中使用 rhea 的 AMQP 1.0 临时队列