to create persistent subscription for Azure service bus using node js

0 votes

So, I want to create a persistent subscription for the Azure service bus using Node Js. At the moment, it only executes successfully once. The following is the code I'm using.

var azure = require('azure');

var azureConnection = "Endpoint=sb:My connection string"

var retryOperations = new azure.ExponentialRetryPolicyFilter();
var serviceBusService = azure.createServiceBusService(azureConnection).withFilter(retryOperations);

serviceBusService.receiveSubscriptionMessage('mytopic01', 'mytopicsub', function (error, receivedMessage) {

    if (!error) {
        // // // Message received and deleted
        console.log(receivedMessage);
    }
});
Apr 9 in IoT (Internet of Things) by Shubham
• 13,190 points
53 views

1 answer to this question.

0 votes

My reference is a similar solution at GitHub provided by Azure Team. Actually, if your client application is an independent node.js application, you set up a cycle-program to receive a message from service bus in the loop, like so;

var azure = require('azure');
var sbService = azure.createServiceBusService(<connection_string>);
function checkForMessages(sbService, queueName, callback) {
  sbService.receiveSubscriptionMessage(queueName, { isPeekLock: true }, function (err, lockedMessage) {
    if (err) {
      if (err === 'No messages to receive') {
        console.log('No messages');
      } else {
        callback(err);
      }
    } else {
      callback(null, lockedMessage);
    }
  });
}
function processMessage(sbService, err, lockedMsg) {
  if (err) {
    console.log('Error on Rx: ', err);
  } else {
    console.log('Rx: ', lockedMsg);
    sbService.deleteMessage(lockedMsg, function(err2) {
      if (err2) {
        console.log('Failed to delete message: ', err2);
      } else {
        console.log('Deleted message.');
      }
    })
  }
}
setInterval(checkForMessages.bind(null, sbService, queueName, processMessage.bind(null, sbService)), 5000);

answered Apr 9 by Upasana
• 8,430 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Azure - What service to use for Arduino data (iot)

That's because the two services do completely ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
70 views
0 votes
1 answer

Using FIWARE to start Cygnus as a Service in IoT Solution

Cygnus is supposed to create /var/run/cygnus/ when started. You ...READ MORE

answered Aug 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
65 views
0 votes
1 answer

Create Azure IoT using ARM Template in Azure

It is not recommended to deploy the ...READ MORE

answered Sep 5, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
134 views
0 votes
1 answer

Integrate IoT device to Azure using MQTT

Today there isn't an official support for ...READ MORE

answered Sep 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
453 views
0 votes
1 answer
0 votes
1 answer

How to send Bitcoins with node.js?

This website https://blockr.io/tx/push will successfully do the bitcoin transaction. You ...READ MORE

answered Jul 20, 2018 in Blockchain by Christine
• 15,790 points
286 views
+1 vote
1 answer

Ethereum Error: authentication needed: password or unlock

First, make sure you have an account. web3.personal.listAccounts If ...READ MORE

answered Aug 8, 2018 in Blockchain by Omkar
• 67,120 points
390 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
59 views
0 votes
1 answer

Azure IoT: Message from cloud to device using Rest API

Firstly, If you get No content response(error ...READ MORE

answered Dec 31, 2018 in IoT (Internet of Things) by Upasana
• 8,430 points
126 views
0 votes
1 answer