azure - 如何确保通过 Azure 服务总线队列接收所有消息?

标签 azure azureservicebus servicebus azure-servicebus-queues

我按照 Microsoft Documentation 中的教程创建了一个服务总线队列。我可以发送和接收消息,但是,只有一半的消息能够通过。从字面上看是一半,只有偶数。

我尝试更改消息频率,但没有任何改变。无论我每 3 秒发送一条消息还是每秒 3 条消息,我在另一端只收到一半消息。

我已经用所有可能的语言运行了示例代码,并且尝试使用 REST API 和批量消息传递,但没有成功。

我还尝试将 Azure Functions 与服务总线队列的特定触发器结合使用。

这是接收函数代码:

module.exports = async function(context, mySbMsg) {
  context.log('JavaScript ServiceBus queue trigger function processed message', mySbMsg);
  context.done();
};

这是发送函数代码:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    var azure = require('azure-sb');

    var idx = 0;
    function sendMessages(sbService, queueName) {
      var msg = 'Message # ' + (++idx);
      sbService.sendQueueMessage(queueName, msg, function (err) {
       if (err) {
         console.log('Failed Tx: ', err);
       } else {
         console.log('Sent ' + msg);
       }
      });
    }

    var connStr = 'Endpoint=sb://<sbnamespace>.servicebus.windows.net/;SharedAccessKeyName=<keyname>;SharedAccessKey=<key>';
    var queueName = 'MessageQueue';

    context.log('Connecting to ' + connStr + ' queue ' + queueName);
    var sbService = azure.createServiceBusService(connStr);
    sbService.createQueueIfNotExists(queueName, function (err) {
      if (err) {
       console.log('Failed to create queue: ', err);
      } else {
       setInterval(sendMessages.bind(null, sbService, queueName), 2000);
      }
    });
};

我希望收到大部分已发送的消息(特别是在完全没有负载的情况下),但我只收到了 50%。

最佳答案

我的猜测是,原因是您只收听该主题的 2 个订阅之一,并且它被设置为在订阅之间拆分消息。此功能用于将工作负载拆分到多个服务。您可以在此处阅读有关主题的信息:https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overviewhttps://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

这里对上面链接的描述进行排序: “分区使用过滤器以可预测且互斥的方式在多个现有主题订阅之间分发消息。当系统横向扩展以处理功能相同的分区中的许多不同上下文(每个分区保存总体数据的子集)时,就会使用分区模式;例如,客户资料信息。通过分区,发布者可以将消息提交到主题中,而无需了解分区模型。然后,该消息将被移动到正确的订阅,然后分区的消息处理程序可以从中检索该消息。”

要检查这一点,您可以查看您的服务总线是否打开了分区或任何其他过滤器。我认为关闭分区应该可以解决您的情况。

关于azure - 如何确保通过 Azure 服务总线队列接收所有消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55355576/

相关文章:

azure - 如何在 Azure 逻辑应用响应组件中进行迭代

git - 如何在azure存储库中区分大小写的git diff?

azure - 如何设计采用文本文件、csv 或任何其他自定义文件并将其加载到 AZURE DB 表中的组件

.net - 使用新库 (Microsoft.Azure.ServiceBus) 发送一条消息,该消息由旧库 (Microsoft.ServiceBus.Messaging) 使用 BodyType - String 读取

c# - 如何向 Azure 移动服务调用添加自己的 header ?

c# - Azure Webjobs ServiceBusTrigger - 达到 MaxDeliveryCount 时执行不同的功能

Azure 服务总线 : transient errors (exceptions) received through the message pump with built-in retry policy. 为什么?

Azure 服务总线 - 放弃的消息返回到同一订阅者

rest - 使用 REST API 将消息发送到 .Net Core Core 中的 azure 服务总线队列

c# - 无法通过基本 C# 应用程序的 Azure 身份验证