使用 Node.js 从 Azure WebJob 轮询 Azure 服务总线队列

2023-12-12

尝试使用用 Node.js 编写的 WebJob 轮询 Azure 服务总线队列。我创建了 2 个 WebJobs。第一个是按需的,并向队列发送 10 条唯一的消息。第二个作业是连续的,并轮询队列中的消息。

遇到以下问题:

  1. 轮询速度很慢。平均需要10分钟左右才能收到10条消息。请参阅下面的示例日志详细信息。这个速度基本没法用。所有的延迟都是因为得到回复receiveQueueMessage。响应时间从 0 秒到约 120 秒不等,平均为 60 秒。

  2. 消息以随机顺序接收。不是先进先出。

  3. 有时消息会被接收两次,即使它们是在 ReceiveAndDelete 模式下读取的(我尝试过不使用读取模式参数,该参数应默认为 ReceiveAndDelete,使用{isReceiveAndDelete:true}{isPeekLock:false}具有相同的结果)。

  4. 当队列为空时,它应该保持接收请求打开一天,但它总是在 230 秒后返回,并显示无消息错误。根据文档,最长为 24 天,所以我不知道 230 秒从何而来:

服务总线中阻塞接收操作的最大超时 排队时间是24天。但是,基于 REST 的超时有一个最大值 55秒。

基本上没有什么像宣传的那样有效。我究竟做错了什么?

发送消息测试作业:

var uuid = require('node-uuid');
var azure = require('azure');
var serviceBus = azure.createServiceBusService(process.env.busSearchConnectionString);
var messagesToSend = 10;

sendMessage(0);

function sendMessage(count)
{
    var message = {
        body: 'test message',
        customProperties: {
            message_number: count,
            sent_date: new Date
        },
        brokerProperties: {
            MessageId: uuid.v4() //ensure that service bus doesn't think this is a duplicate message
        }
    };

    serviceBus.sendQueueMessage(process.env.busSearchQueueName, message, function(err) {

        if (!err) {
            console.log('sent test message number ' + count.toString());
        } else {
            console.error('error sending message: ' + err);
        }

    });

    //wait 5 seconds to ensure messages are received by service bus in correct order
    if (count < messagesToSend) {
        setTimeout(function(newCount) {
            //send next message
            sendMessage(newCount);
        }, 5000, count+1);
    }
}    

接收消息连续作业:

console.log('listener job started');
var azure = require('azure');
var serviceBus = azure.createServiceBusService(process.env.busSearchConnectionString);
listenForMessages(serviceBus);

function listenForMessages(serviceBus)
{
    var start = process.hrtime();
    var timeOut = 60*60*24; //long poll for 1 day
    serviceBus.receiveQueueMessage(process.env.busSearchQueueName, {timeoutIntervalInS: timeOut, isReceiveAndDelete: true}, function(err, message) {

        var end = process.hrtime(start);
        console.log('received a response in %ds seconds', end[0]);

        if (err) {

            console.log('error requesting message: ' + err);
            listenForMessages(serviceBus);

        } else {

            if (message !== null && typeof message === 'object' && 'customProperties' in message && 'message_number' in message.customProperties) {

                console.log('received test message number ' + message.customProperties.message_number.toString());
                listenForMessages(serviceBus);

            } else {

                console.log('invalid message received');
                listenForMessages(serviceBus);

            }

        }

    });
}

示例日志输出:

[05/06/2015 21:50:14 > 8c2504: SYS INFO] Status changed to Running
[05/06/2015 21:50:14 > 8c2504: INFO] listener job started
[05/06/2015 21:51:23 > 8c2504: INFO] received a response in 1s seconds
[05/06/2015 21:51:23 > 8c2504: INFO] received test message number 0
[05/06/2015 21:51:25 > 8c2504: INFO] received a response in 2s seconds
[05/06/2015 21:51:26 > 8c2504: INFO] received test message number 4
[05/06/2015 21:51:27 > 8c2504: INFO] received a response in 1s seconds
[05/06/2015 21:51:27 > 8c2504: INFO] received test message number 7
[05/06/2015 21:51:28 > 8c2504: INFO] received a response in 0s seconds
[05/06/2015 21:51:29 > 8c2504: INFO] received test message number 9
[05/06/2015 21:51:49 > 8c2504: INFO] received a response in 20s seconds
[05/06/2015 21:51:49 > 8c2504: INFO] received test message number 1
[05/06/2015 21:53:35 > 8c2504: INFO] received a response in 106s seconds
[05/06/2015 21:53:35 > 8c2504: INFO] received test message number 1
[05/06/2015 21:54:26 > 8c2504: INFO] received a response in 50s seconds
[05/06/2015 21:54:26 > 8c2504: INFO] received test message number 5
[05/06/2015 21:54:35 > 8c2504: INFO] received a response in 9s seconds
[05/06/2015 21:54:35 > 8c2504: INFO] received test message number 9
[05/06/2015 21:55:28 > 8c2504: INFO] received a response in 53s seconds
[05/06/2015 21:55:28 > 8c2504: INFO] received test message number 2
[05/06/2015 21:57:26 > 8c2504: INFO] received a response in 118s seconds
[05/06/2015 21:57:26 > 8c2504: INFO] received test message number 6
[05/06/2015 21:58:28 > 8c2504: INFO] received a response in 61s seconds
[05/06/2015 21:58:28 > 8c2504: INFO] received test message number 8
[05/06/2015 22:00:35 > 8c2504: INFO] received a response in 126s seconds
[05/06/2015 22:00:35 > 8c2504: INFO] received test message number 3
[05/06/2015 22:04:25 > 8c2504: INFO] received a response in 230s seconds
[05/06/2015 22:04:25 > 8c2504: INFO] error requesting message: No messages to receive
[05/06/2015 22:08:16 > 8c2504: INFO] received a response in 230s seconds    
[05/06/2015 22:04:25 > 8c2504: INFO] error requesting message: No messages to receive

问题是我使用的队列已分区(在 Azure 门户中创建队列时的默认选项)。一旦我创建了一个未分区的新队列,一切都会按预期工作,没有延迟(除了长轮询尝试中奇怪的 230 秒超时)。所以基本上 Node.js 库不适用于分区队列。完全没有。浪费了很多天来弄清楚这一点。将把这个留给其他人。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Node.js 从 Azure WebJob 轮询 Azure 服务总线队列 的相关文章

随机推荐

  • 获取 Recycler View 上单击的项目的位置

    我已经实施了RecyclerView而且效果很好 我有一个ArrayList其中包含回收器视图的数据 每个项目的布局都很复杂 它包含两个frameLayout Framelayout1 包含一个图像和一个文本 framelayout2 包含
  • 不允许使用 HTTP 动词 POST 来访问路径“/”

    整个错误 Server Error in Application The HTTP verb POST used to access path is not allowed Description An unhandled exceptio
  • 多处理时在哪里调用 join()

    在 Python 中使用多处理时 我通常会看到以下示例 join 函数在每个进程实际创建的单独循环中调用 例如 这个 processes for i in range 10 p Process target my func processe
  • 如何找到数组中的第一个空闲键

    我们都知道 数组实际上是 PHP 中的有序树 鉴于此 数组索引 整数键 不需要遵循任何严格的顺序 甚至根本不需要存在 所以 给定一个像这样的数组 array 1 gt A 5 gt B 2 gt C 3 gt D 6 gt E 0 gt F
  • 一旦超出索引,C# 将数组索引值循环回数组开头

    我希望创建一个如下所示的程序 c 顺便说一句 int arr new int 9 some code that puts values 1 0 or 2 in each array element for int i 0 i lt arr
  • 如何在 bash 中使用 getopts 的示例

    我想打电话myscript文件以这种方式 myscript s 45 p any string or myscript h should display help myscript should display help 我的要求是 get
  • 如何在 Ubuntu 操作系统上使用 cron 作业每天运行 php 脚本

    运行命令我正在使用 ubuntu 12 和 lamp 服务器 我想每 1 小时运行一次 php 脚本 我已经创建了一个 crontab 来执行此操作 如果我使用命令 crontab l 检查我的 cron 列表 它会显示如下 Edit th
  • 如何在 R 中将数据帧上传到 ndtv?

    我的目标是使用 R 中的三个包进行动态可视化 ndtv network and networkDynamic包 我创建了一个dataset根据此示例数据集排序的信息网络动态时间可视化研讨会 第 7 页 根据网络动态手册第49页 上传数据集并
  • 在模式弹出窗口中打开外部网站

    我知道 a href http www example com target blank Click here a 打开链接在新标签中 Chrome 和 Firefox 中的默认行为 a href http www example com
  • 通过 jQuery GET 强制“另存为”对话框

    我在下面的 test php 文件代码中调用 jQuery GET 我试图让脚本在生成的 test ini 文件上弹出 另存为 对话框 以允许将其保存在本地 然而 虽然我可以将结果回显给 jQuery 但我似乎无法弹出 另存为 对话框 更新
  • 如何将一系列单元格存储到数组中?

    如果我在单元格 A1 A150 中有一个数据列表 但数量可能会有所不同 有没有办法将其推入数组 而无需单独查看每个单元格来确定它是否为空 这样做超出了我的执行时间 我需要一种更快的方法来存储数据并在数据到达空单元格时停止 以下是我目前的做法
  • 当didUpdateToLocation发生时,iphone在后台发送邮件

    我开始工作 skpsmtpmessage http code google com p skpsmtpmessage 这样我就可以在前台发送邮件 现在我希望在 didUpdateLocation 发生时通过 skpsmtpmessage 在
  • 特定时间段内的多笔交易,受日期范围限制

    我有一个包含交易 人员 交易日期 物品等的数据库 每次有人购买商品时 交易都会存储在表中 如下所示 personNumber TransactionNumber TransactionDate ItemNumber 我想要做的是找到从 20
  • Java观察者更新函数

    我有一个实现观察者的类 当然它需要有更新功能 public void update Observable obs Object obj 谁能解释一下这两个参数代表什么 Observable 当然是我的 observable 但是 我如何通过
  • bash 中的 printf:“09”和“08”是无效数字,“07”和“06”可以

    这是我的 bash 脚本 我只想用零填充一组数字 printf 04d 09 printf 04d 08 printf 04d 07 printf 04d 06 Output rename sh line 3 printf 09 inval
  • 为什么不等待我传递给 Task.Run() 的异步操作?

    我在这里有一种非常奇怪的感觉 我错过了一些东西 但现在我已经在这个问题上苦苦挣扎了几个小时 但无法得到它 我有一种任务调度类 它主要接收它启动的正常同步操作 而不是通过 Task Run 异步操作 但是 当它收到传递的异步操作时 它会返回而
  • 事件侦听器无法与 firebase 查询一起使用

    我正在尝试为我的 firebase 查询脚本创建一个事件侦听器 但它的行为有点奇怪 这是我的脚本 using System Collections Generic using UnityEngine using System Linq us
  • NSAllowsArbitraryLoadsInWebContent in CN1

    我正在尝试解决 Apple 对 Codename One 的 http 限制 根据 iOS Cocoa 密钥文档 NSAllowsArbitraryLoadsInWebContent 将按照以下说明在 iOS 10 上运行 仅适用于要加载的
  • 在 PostgreSQL 中创建数据库的副本

    在 pgAdmin 中将整个数据库 其结构和数据 复制到新数据库的正确方法是什么 Postgres 允许在创建新数据库时使用服务器上任何现有的数据库作为模板 我不确定 pgAdmin 是否为您提供了创建数据库对话框上的选项 但如果没有 您应
  • 使用 Node.js 从 Azure WebJob 轮询 Azure 服务总线队列

    尝试使用用 Node js 编写的 WebJob 轮询 Azure 服务总线队列 我创建了 2 个 WebJobs 第一个是按需的 并向队列发送 10 条唯一的消息 第二个作业是连续的 并轮询队列中的消息 遇到以下问题 轮询速度很慢 平均需