Skip to content

Getting started

Rami edited this page Nov 3, 2019 · 4 revisions

Message Format

{
   "type": "TYPE_1",
   "content": /* your message, can be any type (object, string, init, ...) */
}

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());