1.0.1 • Published 6 years ago
queue-router v1.0.1
queue-router
Simple Router For Queues
Message Format
{
   "type": "TYPE_1",
   "content": { /* your message */ }
}Usage
Create Router (Routes messages to specific handler)
  const Router = require('queue-router').Router;
  const router = new Router();
  router.add('TYPE_1', {
      handler: function(messageContent, attributes) { // Required
          // your handling code
      },
      validation: { // Optional
          schema: // Joi schema, https://github.com/hapijs/joi 
      }
  });Create Worker (Pulling message from queue and send them to the router)
  const workerFactory = require('queue-router').workerFactory;
  const worker = workerFactory.create(workerFactory.Types.SQS, router, config);
  worker.init().then(() => worker.start());workerFactory
workers generator
Functionalities
create(worker_type, router, config)
Create new worker
Entities
Types
Includes all types of worker to listen
SQS
AWS SQS resource config:
- queue- 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)
- queueUrl: url to sqs
 
- credentials
 
- aws
worker
Functionalities
init()
inititalize worker
start()
start worker (start listen to queue and pull messages)
Router
Functionalities
add(message_type, config_object)
add new route
Entities
config_object
route configuration config:
- handler: handler function
- validation: validation using Joi 
Worker Events
- error: Fired on general errors.
- message_error: Fired when an error occurs processing the message.
- message_received: Fired when a message is received.
- message_processed: Fired when a message is successfully processed and removed from the queue.
- stopped: Fired when the consumer finally stops its work.
- idle: Fired when the queue is empty (All messages have been consumed).
Run Tests
npm testLicense
MIT