@juntoz/azure-service-bus-sender
v2.0.3
Published
Quick logger that enables the function to log to the default logger (console) and also to papertrail
Downloads
97
Readme
azure-service-bus-sender
Wrapper for Azure Service Bus to send messages to topics and queues.
This library was created to provide a singleton for bus client, topic client and sender to be able to reuse them which is the recommended pattern (expensive objects).
Install
npm install @juntoz/azure-service-bus-sender
Use it
const ASBWrapper = require('@juntoz/azure-service-bus-sender');
// create a singleton, this is important because asb is a expensive object
var asb = new ASBWrapper();
async function main_azfunc() {
// NOTE: the bus name is important because it is the key to cache the clients.
var busName;
var busConnectionString, busTopicName, busQueueName;
// create or reuse the topic sender
var ts = asb.createTopicSender(busName, busConnectionString, busTopicName);
// send the message
await ts.send(myMsg);
// create or reuse the queue sender
var qs = asb.createQueueSender(busName, busConnectionString, busQueueName);
// send the message
await qs.send(myMsg);
}
module.exports = main_azfunc;
Cleanup
The class also has a cleanup method which can be called to close the bus client connections. In Azure Functions, this is not really needed to be called, however, if this is used outside AzF, then you should call it at the end of the application.