Since my background is in Microsoft Development, I have spent a fair bit of time playing in the Azure World. One of the offerings in Azure is the Azure Storage Account which comes with a basic Queuing mechanism. I have used Storage Account Queues on a previous project, and thought it would be a perfect fit for an Alexa Skill I had been working on.
The code to drop a message into an Azure Storage Account Queue is surprisingly simple. Here is the code that is now part of my Utilities module…
const azure = require(‘azure-storage’);
module.exports = {
/*
—————————————————————————————–
Function Name : sendMessageToAzureQueue
Purpose : Drops a message into an Azure Storage Account Queue
—————————————————————————————–
*/
sendMessageToAzureQueue: function (messageToSend) {
var storageAccount = process.env.AZURE_STORAGE_ACCOUNT_NAME;
var storageAccessKey = process.env.AZURE_STORAGE_ACCESS_KEY;
var host = process.env.AZURE_STORAGE_HOST;
var queueSvc = azure.createQueueService(storageAccount, storageAccessKey, host);
queueSvc.createQueueIfNotExists(‘verbalbusiness-applicationmessages’, function (error, results, response) {
if (!error) {
queueSvc.createMessage(‘verbalbusiness-applicationmessages’, Buffer.from(messageToSend).toString(“base64”), function (error, results, response) {
if (!error) {
return true;
}
else{
return false;
}
});
}
else{
return false;
}
});
}
Here is a link to the ‘azure-storage’ npm package that is the backbone of the whole thing
https://www.npmjs.com/package/azure-storage
Also, you will need Dotenv which is a module that loads environment variables from a .env
file. You can find it at
https://www.npmjs.com/package/dotenv
You will of course need to setup an Azure Storage Account in the Azure Portal. Once that Storage Account is setup, you will need the Storage Account Name, Access Key and Host Name, which you can also get from the Azure Portal.
Those values can then be inserted into the .env file as shown below….
AZURE_STORAGE_ACCOUNT_NAME = “Your Storage Account Name”
AZURE_STORAGE_ACCESS_KEY = “Your Storage Account Access Key”
AZURE_STORAGE_HOST = “Your Storage Account Host Name”
Once that is all in place, you should be good to go.
You can now have your Alexa Skill Service code drop messages into an Azure Storage Account Queue and let a background process handle those messages while your Skill Code continues along with more important tasks.
Thanks for reading.