Created
March 18, 2018 21:32
-
-
Save scionwest/106b0ec181baa9576825c8506fadd885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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