0.0.13 • Published 5 years ago

sqs-router v0.0.13

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

sqs-router

SQS reader with simple router by type

NPM version NPM Downloads Node.js Version

SQS Message Format

{
   "type": "TYPE_1",
   "content": { /* your message */ }
}

Usage

  const sqsWorkerFactory = require('sqs-worker').workerFactory;

  const sqsWorker = new sqsWorkerFactory.create('/tmp/controllers', 'https://sqs.us-east-1.amazonaws.com/123123/my-queue', options);
  sqsWorker.on('error', console.error);
  (await sqsWorker.init()).start();
 |-- tmp
 |---- controllers
 |-------- myController.js

myController.js

const Joi = require('joi');
const BaseController = require('sqs-worker').BaseController;

class myController extends BaseController {
    constructor() {
        super();
    }

    get type() {
        return 'TYPE_1';
    }
    
    get messageContentSchema() {
        // Joi schema for message.content (https://github.com/hapijs/joi)
        // schema example: 
        return Joi.object({
            age: Joi.number().required()
        }).required();
    }

    async initDefaults() {
        return this;
    }
    
    async handleMessage(messageContent) {
        // your handling code
    }
}

module.exports = myController;

Configuration

options
  • aws
    • credentials
      • region: (default from env AWS_REGION)
      • accessKeyId: (default from env AWS_ACCESS_KEY_ID)
      • secretAccessKey: (default from env AWS_SECRET_ACCESS_KEY)
    • batchSize: Size of batch (default 10)

Events

  • error: notify failures during the message processing
  • message: notify status of the message processing (PROCESSING, PROCEED)

Run Tests

npm test

License

MIT

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago