0.1.1 • Published 9 years ago

seneca-sqs-transport v0.1.1

Weekly downloads
2
License
MIT
Repository
-
Last release
9 years ago

seneca-sqs-transport

A Seneca.js transport plugin to transfer messages over SQS.

ES6 transpiling

TODO Remove this documentation piece before publishing to npm repository

To be able to use the module in our Meteor application, a transpiling step via babel was added. Please note that both src and lib directories are added to git, as module is installed via direct link, not via npm, so compiled code needs to be there.

TODO Set up .gitignore and .npmignore before publishing to npm repository

Listener

Listener polls preconfigured SQS queue for messages, processes requests and sends responses back to clients. By default each request message contains a property with queue URL to send the response to.

If that property is empty, the client is considered to be not interested in the response data and the message is just silently executed without sending any responses.

A simple listener may look like this:

const seneca = require('seneca');

seneca({ timeout: 30000 })
  .use('seneca-sqs-transport')
  .add('role: test, cmd: echo', (args, done) => {
    done(null, { message: args.message });
  })
  .listen({
    type: 'sqs',
    accessKeyId: process.env.SQS_KEY,
    secretAccessKey: process.env.SQS_SECRET_KEY,
    queueUrl: process.env.SQS_QUEUE_URL,
  });

Client

Client sends request messages to the preconfigured SQS queue. Also it creates new personal queue on startup to receive response messages over it. That queue URL is sent over as a request message property, so listener knows whom to reply to.

There is an option to skip creating that personal response queue. In that case client does not wait till listener executes an action. Client just waits for SQS to accept the request message. Then action callback is immediately executed using AWS.SQS.sendMessage result as an argument.

A simple client may look like this:

const seneca = require('seneca');
const client = seneca({ timeout: 30000 })
  .use('seneca-sqs-transport')
  .client({
    type: 'sqs',
    accessKeyId: process.env.SQS_KEY,
    secretAccessKey: process.env.SQS_SECRET_KEY,
    queueUrl: process.env.SQS_QUEUE_URL,
    responseQueuePrefix: 'test_echo_',
  });

setInterval(() => {
  client.act('role: test, cmd: echo, message: hello', console.log);
}, 2000);

Options

These are the default options used by the plugin:

const defaults = {
  sqs: {
    type: 'sqs',
    accessKeyId: '',
    secretAccessKey: '',
    region: 'us-east-1',
    queueUrl: '',
    responseQueuePrefix: '',
    noResponse: false,
    maxNumberOfMessages: 1,
  },
};
OptionTypeDescription
accessKeyIdStringAWS access key
secretAccessKeyStringAWS secret key
regionStringAWS region
queueUrlStringSQS queue URL to send (client) and receive (listener) messages to/from.
responseQueuePrefixStringPrefix to append to the name of client's personal response queue name.
noResponseBooleanDefines if client should wait for server response to come. If set to true client callback is executed immediately after sending a message.
maxNumberOfMessagesIntegerThe number of simultaneously processed messages.

Examples

There are simple client and listener examples in examples directory. They rely on the following environment variables to be defined:

  • SQS_KEY
  • SQS_SECRET_KEY
  • SQS_QUEUE_URL

TODO

  • Tests
  • Remove AWS information from seneca logs
  • Handle occasional client exception when it is terminated while processing the response
0.1.1

9 years ago

0.1.0

9 years ago