Skip to content

Instantly share code, notes, and snippets.

@XavierGeerinck
Last active March 31, 2018 08:35
Show Gist options
  • Save XavierGeerinck/a04615baf36d90504cdee651d0c50519 to your computer and use it in GitHub Desktop.
Save XavierGeerinck/a04615baf36d90504cdee651d0c50519 to your computer and use it in GitHub Desktop.
const azure = require('azure-storage');
const config = require('./config');
const queueService = azure.createQueueService(config.azureStorageAccount, config.azureStorageAccessKey);
queueService.createQueueIfNotExists(config.queueName, (err, result, res) => {
if (err) {
console.error(err);
return;
}
if (result.created) {
console.log(`[Queue - Sender] Queue ${config.queueName} did not exist, created it`);
}
// We will add 1 message per 500ms
setInterval(() => {
const message = {
temperature_sensor: {
id: `sensor_${Math.floor((Math.random() * 10) + 1)}`,
value: ((Math.random() * 41) - 10).toFixed(2),
createdAt: new Date()
}
};
queueService.createMessage(config.queueName, JSON.stringify(message), (err, result, res) => {
if (err) {
console.error(`[Queue - Sender] An error occurred: ${JSON.stringify(err)}`);
}
console.log(`[Queue - Sender] Sent: ${JSON.stringify(message)}`);
});
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment