适用于 Node JS 的 Azure SDK 在 Azure 工作者角色中不起作用

Azure SDK for Node JS not working in Azure worker Role

我正在使用这段代码从我的 node.js 文件 运行 在 Azure 辅助角色中调用服务总线队列。

var azure = require('azure'),
    config = require('./config');
var serviceBusClient = azure.createServiceBusService(config.sbConnection);
console.log("Start");
serviceBusClient.getQueue("myqueue", function (error, queue) {
    if(error){
        console.log(error);
    }
   console.log(queue);
});
console.log("End");

在此代码工作者角色中,仅记录 "start" 和 "end",但 getQueue API 不工作且未抛出任何错误,它在我的本地计算机上工作正常并记录响应。

我使用您的 node.js 脚本代码在新的云服务中进行了测试,并部署到 Azure。我配置了 .csdef 文件以将输出通过管道传输到日志文件中,例如:<ProgramEntryPoint commandLine="node.cmd .\worker.js &gt; sblog.txt" setReadyOnProcessStart="true" /> 以检查 node.js 脚本的输出。

我这边一切正常。您能否确认您的队列中是否有消息,以及您的 .csdef 文件中是否有任何特定配置。

更新

根据https://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/的描述:

If you are hosting your application in an Azure Cloud Service (web or worker role,) and it is the first time you have deployed the application, Azure will attempt to use the same version of Node.js as you have installed on your development environment if it matches one of the default versions available on Azure.

并且我们可以通过powershell命令查看云服务中可用的nodejs版本:Get-AzureServiceProjectRoleRuntime。可用版本列表为:0.6.170.6.200.8.40.8.220.8.260.10.21.

如果您想使用您的自定义 nodejs 版本,您可以将整个 node.js execute application 文件夹打包到您的云服务应用程序中。并修改您的云服务应用程序中的 node.cmd 文件,以指示 node.js 在您的云服务包中执行应用程序的路径。