Skip to content
/ sqs-loop Public

SQS polling lib to ease the creation of consumers that run forever.

License

Notifications You must be signed in to change notification settings

daime/sqs-loop

Repository files navigation

SQS-LOOP

SQS polling lib to ease the creation of consumers that run forever.

npm install --save sqs-loop
const sqsLoop = require('sqs-loop');

sqsLoop.aws.config.update({
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    region: 'us-east-1'
});

const params = {
    QueueName: 'awesome-queue', // auto create and resolves queue url
    VisibilityTimeout: 5,
    MaxNumberOfMessages: 5,
    WaitTimeSeconds: 20
};

// Callback will be called once per message in parallel by MaxNumberOfMessages
sqsLoop.loop(params, message => {
    const body = JSON.parse(message.Body);

    /*
     * work with our message
     */

    // If we want to loop no further
    // return sqsLoop.stop();

    // If we want to keep the messsage in SQS
    // return sqsLoop.keep();
});

Return values

  • sqsLoop.stop(): stops the loop and resolves the promise
  • sqsLoop.keep(): avoid removal of the message from SQS queue
  • promise rejections: keep the message on the queue.
  • promise resolves or normal returns: removes the message from SQS queue

About

SQS polling lib to ease the creation of consumers that run forever.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published