Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created March 18, 2018 21:32
Show Gist options
  • Save scionwest/106b0ec181baa9576825c8506fadd885 to your computer and use it in GitHub Desktop.
Save scionwest/106b0ec181baa9576825c8506fadd885 to your computer and use it in GitHub Desktop.
module.exports = function() {
var azure = require('azure');
var topic = "foo-bar";
var connectionString = "Endpoint=sb://...";
console.log("Configuring Service Bus.");
var serviceBusService = azure.createServiceBusService(connectionString);
var movies = [];
for(count = 0; count < 400000; count++) {
movies.push({id: count});
}
serviceBusService.createTopicIfNotExists(topic, function(error) {
if (error) {
console.log(`Failed to get the Service Bus topic`);
return;
}
console.log("Service Bus setup.");
var message = {
body: '',
customProperties: {
messageNumber: 0
}
}
// wait for al 400,000 to finish.
for(index = 0; index < movies.length; index++) {
message.customProperties.messageNumber = index;
message.body = JSON.stringify(movies[index]);
serviceBusService.sendTopicMessage(topic, message, function(error) {
if (error) {
console.log(`Failed to send topic message for ${message.body}: ${error}`);
return;
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment