Home

Awesome

Azure SB Queue Watcher

Dependency Status devDependency Status

Job worker around Azure Service Bus Queues. It exposes a clean interface to watch for messages in a failsafe way.

Azure/azure-sdk-for-node does not exposes a simple way to watch for messages and mark them as completed.

This is the reason to exist of this module.

Install

npm install azure-sb-queue-watcher --save

Example

var azure = require('azure');
var AzureSBQueueWatcher = require('azure-sb-queue-watcher');

var myServiceBus = azure.createServiceBusService();
var watcher = new AzureSBQueueWatcher({
  serviceBus: myServiceBus,
  queueName: 'hello'
});

watcher.start();

watcher.on('message', newMessage);
watcher.on('error', console.error);

function newMessage(message, done) {
  console.log(message);
  
  // fake async processing
  setTimeout(done, 200);
}

API

var watcher = new AzureSBQueueWatcher(opts)

opts.serviceBus is required and must be a ServiceBusService object.

You usually create them like this:

var azure = require('azure');
var serviceBusService = azure.createServiceBusService();

opts.queueName is the service bus queue name you want to watch.

opts.concurrency is the number of messages you want to get from the queue at once. It defaults to 1. It all depends on how much messages you can deal with given you CPU power.

opts.timeout is the message processing timeout (in ms). After this timeout, the message is released to be consumed by others. Defaults to 30s.

watcher.start()

Start watching for messages.

watcher.stop()

Stop watching for messages.

watcher.on('message', message, done)

New message arrived.

message contains the original azure service bus queue message.

done is a callback you must call when you have finished dealing with the message. You must call done.

watcher.on('error')

Emitted when an error occurs. Error cases: