Search code examples
node.jsazureazure-worker-rolesazure-sdk

Azure SDK for Node JS not working in Azure worker Role


I am using this piece of code to call the service bus queue from my node.js file running in Azure Worker Role .

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");

In this code worker role only log "start" and "end" but getQueue API is not working and not throwing any error and it is working fine on my local machine and logging the response.


Solution

  • I tested in a new Cloud Service with your node.js script code, and deploy to Azure. And I configed the .csdef file to pipe the output into a log file, like: <ProgramEntryPoint commandLine="node.cmd .\worker.js &gt; sblog.txt" setReadyOnProcessStart="true" /> to check the output of the node.js script.

    Everything worked fine on my side. Could you please confirm whether you have messages in your queue, and whether you have any specific configurations in your .csdef file.

    update

    According the description at 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.

    And we can check the available nodejs version in cloud service via the powershell command: Get-AzureServiceProjectRoleRuntime. The available version list is :0.6.17,0.6.20,0.8.4,0.8.22,0.8.26 and 0.10.21.

    If you want to use your custom nodejs version, you can package the entire node.js execute application folder into your cloud service application. And modify the node.cmd file in your cloud service application to direct the node.js execute application's path in your cloud service package.