Skip to content

Instantly share code, notes, and snippets.

@ypcode
Created March 7, 2020 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/a762d4a0c93f8edf593fafcb265c13c6 to your computer and use it in GitHub Desktop.
Save ypcode/a762d4a0c93f8edf593fafcb265c13c6 to your computer and use it in GitHub Desktop.
import * as azure from "azure-storage";
let _queueService = null;
const getQueueService = () => {
if (!_queueService) {
_queueService = azure.createQueueService();
}
return _queueService;
}
export const addMessageToQueue = async (queue: string, message: string): Promise<void> => {
return new Promise((resolve, reject) => {
const queueService = getQueueService();
queueService.createQueueIfNotExists(queue, (error, results, response) => {
if (!error) {
const base64EncodedMessage = new Buffer(message).toString("base64");
queueService.createMessage(queue, base64EncodedMessage, (err, msgResult, msgResp) => {
if (err) {
reject("Could not send message to queue");
}
resolve();
})
} else {
reject("Queue could not be created.");
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment