queue-connector
Provides an abstraction layer for various Cloud providers' queue implementation, like AWS SQS, Azure Service bus, etc.
Last updated 4 years ago by jaydp17 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install queue-connector 
SYNC missed versions from official npm registry.

queue-connector

Provides an abstraction layer for various Cloud providers' queue implementation, like AWS SQS, Azure Service bus, etc.

Installation

$ npm install queue-connector

Usage

Using the queue with AWS SQS

const QueueConnector = require('queue-connector');
const sqs = new QueueConnector.AwsProvider({
  accessKeyId: awsConfig.accessKeyId,
  secretAccessKey: awsConfig.secretAccessKey,
  region: awsConfig.sqs.region
}, sqsQueueUrl);
const queue = new QueueConnector.Queue(sqs);

// send a message
const msg = {a: '1', b: '2'}; // whatever data you want to send
queue.sendMessage(JSON.stringify(msg), (err, data) => {
  // handle callback
});

// receive a message
queue.receiveMessage((err, msg) => {
  console.log(msg.body); // msg as string '{"a": "1", "b": "2"}'
  console.log(msg.bodyAsJSON); // msg as JSON {a: '1', b: '2'}
  
  // delete a message, when processing done
  msg.remove((err, info) => {
    // removes the message from the queue
  });
});

The queue can also be configured to connect to Azure Service Bus with the same API.

const QueueConnector = require('queue-connector');
const serviceBusConnectionString; // get this from Azure portal
const serviceBus = new QueueConnector.AzureProvider(serviceBusConnectionString, queueName);
const queue = new QueueConnector.Queue(serviceBus);

// use the queue object with the same API as the above example

API

new AwsProvider(awsCredentials, sqsQueueUrl, [options])

Creates a new AWS SQS queue provider.

  • awsCredentials : the same awsCredentials that aws-sdk takes
  • sqsQueueUrl : the queue url provided by AWS
  • [options] :
    • WaitTimeSeconds: The request timeout for long polling

new AzureProvider(connStr, queueName, [options])

Creates a new Azure Service Bus queue provider

  • connStr : Connection string to the Service Bus
  • queueName : Name of the queue
  • [options] :
    • timeoutIntervalInS: The request timeout for long polling

Adding more providers

Currently this lib has only AWS SQS and Azure Service Bus provider, if you need any more providers, please feel free to send in a pull request :)

Current Tags

  • 1.0.2                                ...           latest (4 years ago)

3 Versions

  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |