@gasbuddy/configured-sqs-client

    1.9.0 • Public • Published

    configured-sqs-client

    Node CI

    A small wrapper around the AWS SQS sdk and sqs-consumer to allow configuration from confit. Unlike configured-rabbitmq-client, most queue configuration for SQS is done OUTSIDE of the infrastructure here (assumedly will be terraform or similar). So this module focuses on publishing and consuming messages, but with as similar an configuration specification as possible.

    Usage

    See the test directory for sample usage. To send a message, you must configure a logical queue, something like:

    {
      region: 'us-east-1',
      queues: {
        basic: 'basic_queue'
      }
    }
    

    Now, you can publish to this queue using:

      configuredSqsClient.publish(req, 'basic', { some: 'message' });
    

    To receive this message, you would subscribe:

      sqs.subscribe(context, 'basic', async (req, message, envelope) => {
        // Do stuff, await stuff, throw errors, whatever
      });
    

    If your handler throws an error, the redrive policy of the queue takes over. However, if your handler marks that error with a property "deadLetter" that is either true or the name of another queue, the failed attempt will be published on the target queue (either the deadLetter property of the queue that was configured in your configured-sqs-client config, or the queue specified in the deadLetter error property).

    Compression

    Max message size allowed through SQS is 256kb. You can compress/deflate your message if you think it could go over that limit.

      configuredSqsClient.publish(req, 'basic', { some: 'message' }, { compression: true });
    

    The deflated message will automatically be inflated before delivering to a consumer

    Testing this package

    docker run -p 9324:9324 gasbuddy/sqs-mock:latest
    npm run test
    

    Keywords

    Install

    npm i @gasbuddy/configured-sqs-client

    DownloadsWeekly Downloads

    113

    Version

    1.9.0

    License

    MIT

    Unpacked Size

    122 kB

    Total Files

    26

    Last publish

    Collaborators

    • djmax