我编写了一个小型测试节点应用程序,它循环并将消息添加到队列(天蓝色存储队列),如下所示:
var queueService = azure.createQueueService();
var queueName = 'taskqueue';
// other stuff like check if created
// loop called after queue is confirmed
for (i=0;i<1000;i++){
queueService.createMessage(queueName, "Hello world!", null, messageCreated);
}
// messageCreated does nothing at the moment, just logs to console
我正在尝试重写它来处理说 100 万个创建使用异步来控制并行运行的工作函数的数量。这比什么都重要。
https://github.com/caolan/async#queue
这是异步队列的基本设置,我不知道我需要更改什么。我认为以下内容不会起作用:
var q = async.queue(function (task, callback) {
queueService.createMessage(queueName, task.msg, null, messageCreated);
callback();
}, 100);
// assign a callback. Called when all the queues have been processed
q.drain = function() {
console.log('all items have been processed');
}
// add some items to the queue
for(i=0;i<1000000;i++) {
q.push({msg: 'Hello World'}, function (err) {
console.log('finished processing foo');
});
console.log('pushing: ' + i);
}
我不太了解如何将它们与异步结合在一起。