-
-
Save ypcode/a762d4a0c93f8edf593fafcb265c13c6 to your computer and use it in GitHub Desktop.
This file contains 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
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