Simple scaffolding for applications that produce SQS messages

Overview

sqs-producer

NPM downloads Build Status Code Climate Test Coverage

Enqueues messages onto a given SQS queue

Installation

npm install sqs-producer

Usage

const { Producer } = require('sqs-producer');

// create simple producer
const producer = Producer.create({
  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
  region: 'eu-west-1'
});

// create custom producer (supporting all opts as per the API docs: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#constructor-property)
const producer = Producer.create({
  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
  region: 'eu-west-1',
  accessKeyId: 'yourAccessKey',
  secretAccessKey: 'yourSecret'
});

// send messages to the queue
await producer.send(['msg1', 'msg2']);

// get the current size of the queue
const size = await producer.queueSize();
console.log(`There are ${size} messages on the queue.`);

// send a message to the queue with a specific ID (by default the body is used as the ID)
await producer.send([{
  id: 'id1',
  body: 'Hello world'
}]);

// send a message to the queue with
// - delaySeconds (must be an number contained within 0 and 900)
// - messageAttributes
await producer.send([
  {
    id: 'id1',
    body: 'Hello world with two string attributes: attr1 and attr2',
    messageAttributes: {
      attr1: { DataType: 'String', StringValue: 'stringValue' },
      attr2: { DataType: 'Binary', BinaryValue: new Buffer('binaryValue') }
    }
  },
  {
    id: 'id2',
    body: 'Hello world delayed by 5 seconds',
    delaySeconds: 5
  }
]);

// send a message to a FIFO queue
//
// note that AWS FIFO queues require two additional params:
// - groupId (string)
// - deduplicationId (string)
//
// deduplicationId can be excluded if content-based deduplication is enabled
//
// http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queue-recommendations.html
await producer.send({
  id: "testId",
  body: 'Hello world from our FIFO queue!',
  groupId: 'group1234',
  deduplicationId: 'abcdef123456' // typically a hash of the message body
});

Development

Test

npm test

Coverage

For coverage report, run the command:

npm run coverage

Lint

To check for problems using ESLint

npm run lint

Contributing

See contributing guildlines

Comments
  • es5 -> es6, node -> 8, callbacks -> promises, jshint -> eslint, drop lodash dep., audit -> 0 vuln.

    es5 -> es6, node -> 8, callbacks -> promises, jshint -> eslint, drop lodash dep., audit -> 0 vuln.

    This sqs-producer is getting very popular year after year.

    image

    The node.js has moved to ES6 and promises a few years ago.

    I believe it's time to release version 2.0

    This PR brings the long needed support of promises and async/await syntax.

    Full list of changes:

    • got rid of callbacks, only promises are supported now
    • No logic changes. At all!
    • same for the unit tests
    • added "engines": { "node": ">=8.0.0" } to package.json
    • removed node versions 4 and 6 from travis.yml, added 10 and 12
    • replaced jshint with eslint for simplicity and better ES6 support
    • Updated README with the v2.0 breaking changes
    • Removed lodash as a dependency. It was used only once in the code base.
    • Upgraded nyc dependency to kill all npm audit vulnerability warnings
    • Updated .jsbeautifyrc, I avoided a breaking change the package had some time ago
    • Updated .npmignore because coverage report was published to NPM
    • updated CONTRIBUTING.md with a tip how to run js-beautify

    Now, how would I get this published @nspragg @niklasR ?

    enhancement 
    opened by koresar 8
  • Support FIFO queue required params

    Support FIFO queue required params

    Use of FIFO queues requires aws-sdk v2.7.4+ but these changes shouldn't break any backwards compatibility.

    Coverage

    =============================== Coverage summary ===============================
    Statements   : 95.56% ( 86/90 )
    Branches     : 87.27% ( 48/55 )
    Functions    : 100% ( 16/16 )
    Lines        : 96.59% ( 85/88 )
    ================================================================================
    
    opened by jhead 6
  • Add support for DelaySeconds and MessageAttributes props

    Add support for DelaySeconds and MessageAttributes props

    Hi!

    Based on the work of @athibaud, I added the support for DelaySeconds and MessageAttributes.

    I did not have time to add any test, but I wanted to know first if this was of any interest for you, and if you'd like to merge the pull request once I provide some tests.

    Have a nice one,

    Clément

    opened by dieppe 6
  • Control over message id

    Control over message id

    we needed to provide SQS message id's so this PR is a proposed solution.

    simply adds the possibility for messages to be objects of shape {id, body}. i don't know what kind of messages you usually send but we send small JSON stringifed objects so using that as the id was a bit ugly.. there's maybe a bit too much 'error handling' for your liking..

    let us know what you think.

    cheers!

    opened by athibaud 6
  • Producer.send message input type added

    Producer.send message input type added

    Description

    Added message type support in .send method

    Motivation and Context

    https://github.com/bbc/sqs-producer/issues/51

    Types of changes

    • [x] Bug fix (non-breaking change which fixes an issue)

    Checklist:

    • [x] My code follows the code style of this project.
    • [x] My change DONT requires a change to the documentation.
    • [x] I have read the CONTRIBUTING document.
    • [x] All new and existing tests passed.
    enhancement 
    opened by qvantor 4
  • Expose the Producer object instead of just the create function

    Expose the Producer object instead of just the create function

    I wanted to Promisify the Producer class using Bluebird and realized that it wasn't even accessible to me to do so. Please expose class itself instead of just the create function.

    opened by offero 4
  • [Bug]: `npm link sqs-producer` does not work in new v3

    [Bug]: `npm link sqs-producer` does not work in new v3

    Describe the bug

    Install globally. Link it. The npm link fails.

    Your minimal, reproducible example

    npm i -g sqs-producer && npm link sqs-producer

    Steps to reproduce

    > npm i -g sqs-producer
    > npm link sqs-producer
    npm ERR! code 127
    npm ERR! path ~/.nvm/versions/node/v16.18.1/lib/node_modules/sqs-producer
    npm ERR! command failed
    npm ERR! command sh -c -- npm run build
    npm ERR! > [email protected] build
    npm ERR! > npm run clean && tsc
    npm ERR! 
    npm ERR! 
    npm ERR! > [email protected] clean
    npm ERR! > rm -fr dist/*
    npm ERR! sh: tsc: command not found
    

    Expected behavior

    No errors. sqs-producer installed globally and working fine.

    How often does this bug happen?

    Every time

    Screenshots or Videos

    No response

    Platform

    All

    Package version

    3.0, 3.1

    AWS SDK version

    No response

    Additional context

    Offtopic: This bug template is a bit annoying. It should not mandate for "minimal reproducible example" as a URL

    bug triage 
    opened by koresar 3
  • feat: upgrading to aws-sdk-v3

    feat: upgrading to aws-sdk-v3

    Alongside sqs-consumer (being upgraded here: https://github.com/bbc/sqs-consumer/pull/252), we should upgrade sqs-producer to aws-sdk-v3.

    Ideally this should happen at the same time.

    This PR aims to do that.

    opened by nicholasgriffintn 3
  • Wait for message result

    Wait for message result

    I trying to use this package in microservice context. I need to send a message and wait for the result, for example, send a filter and get the list of objects. How can I wait to get the message results?

    Thanks!

    question Stale 
    opened by neumartin 3
  • The Documentation isn't up to date

    The Documentation isn't up to date

    Describe the bug In the docs, it says that we can pass accessKeyId and secretAccessKey to the Producer.create method, but we can only pass an SQS object, the README need an update

    screenshots image image

    bug 
    opened by Pierre-Monier 3
  • queueUrl should not be possibly undefined in ProducerOptions

    queueUrl should not be possibly undefined in ProducerOptions

    The problem There is code to validate that queueUrl isn't undefined, it adds extra logic, I think it's better if this logic is directly in the ProducerOptions type Suggested solution Change ProducerOptions type, set queueUrl as a string instead of an undefined | string

    feature-request Stale 
    opened by Pierre-Monier 3
Releases(v3.1.0)
  • v3.1.0(Dec 18, 2022)

    What's Changed

    • chore: Making queueurl required in interface by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/87
    • chore: exporting produceroptions as a type by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/88

    Full Changelog: https://github.com/bbc/sqs-producer/compare/v3.0.1...v3.1.0

    Source code(tar.gz)
    Source code(zip)
  • v3.0.1(Dec 16, 2022)

    Fix: release had no build / prepublish command was deprecated

    Full Changelog: https://github.com/bbc/sqs-producer/compare/v3.0.0...v3.0.1

    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Dec 16, 2022)

    What's Changed

    • chore: adding eslint and prettier by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/85
    • feat: upgrading to aws-sdk-v3 by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/86

    Full Changelog: https://github.com/bbc/sqs-producer/compare/v2.2.0...v3.0.0

    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Dec 9, 2022)

    What's Changed

    • Fixing producer.JS file import. It should be TS by @koresar in https://github.com/bbc/sqs-producer/pull/50
    • Fix typo in code in README by @fabulator in https://github.com/bbc/sqs-producer/pull/48
    • Producer.send message input type added by @qvantor in https://github.com/bbc/sqs-producer/pull/54
    • Bump lodash from 4.17.15 to 4.17.20 by @dependabot in https://github.com/bbc/sqs-producer/pull/57
    • chore: improving documentation and CI by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/83
    • update readme : create custom producer with accessKeyId / secretAccessKey by @cokia in https://github.com/bbc/sqs-producer/pull/75
    • chore: updating dependencies by @nicholasgriffintn in https://github.com/bbc/sqs-producer/pull/84

    New Contributors

    • @fabulator made their first contribution in https://github.com/bbc/sqs-producer/pull/48
    • @qvantor made their first contribution in https://github.com/bbc/sqs-producer/pull/54
    • @nicholasgriffintn made their first contribution in https://github.com/bbc/sqs-producer/pull/83
    • @cokia made their first contribution in https://github.com/bbc/sqs-producer/pull/75

    Full Changelog: https://github.com/bbc/sqs-producer/compare/v2.0.0...v2.2.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(May 14, 2020)

  • v1.6.3(Feb 4, 2019)

  • v1.6.2(Nov 17, 2017)

  • v1.6.1(Oct 31, 2017)

  • v.1.6.0(Oct 31, 2017)

  • v1.5.0(Dec 9, 2016)

  • v1.4.0(Nov 2, 2016)

  • v1.3.4(May 2, 2016)

  • v1.3.3(Feb 29, 2016)

  • v1.3.2(May 18, 2015)

  • v1.3.1(Mar 13, 2015)

  • v1.3.0(Mar 13, 2015)

  • v1.2.0(Feb 25, 2015)

  • v1.0.0(Dec 17, 2014)

Owner
BBC
Open source code used on public facing services, internal services and educational resources.
BBC
Application structure for new adonis app, think of it as scaffolding a new project

AdonisJs Application This repo is the pre-configured project structure to be used for creating ambitious web servers using AdonisJs. Make sure to star

AdonisJS Framework 375 Oct 15, 2022
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top of TypeScript & JavaScript (ES6, ES7, ES8) 🚀

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest is a framework for building efficient,

nestjs 53.2k Dec 31, 2022
A framework for real-time applications and REST APIs with JavaScript and TypeScript

A framework for real-time applications and REST APIs with JavaScript and TypeScript Feathers is a lightweight web-framework for creating real-time app

Feathers 14.3k Jan 1, 2023
Use full ES2015+ features to develop Node.js applications, Support TypeScript.

ThinkJS Use full ES2015+ features to develop Node.js applications, Support TypeScript. 简体中文文档 Installation npm install -g think-cli Create Application

ThinkJS 5.3k Dec 30, 2022
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers

Derby The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers. Derby includes a powe

DerbyJS 4.7k Dec 23, 2022
LoopBack makes it easy to build modern API applications that require complex integrations.

LoopBack makes it easy to build modern applications that require complex integrations. Fast, small, powerful, extensible core Generate real APIs with

StrongLoop and IBM API Connect 4.4k Jan 4, 2023
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.

Functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. Ecosystem Name Description @marblejs/core F

Marble.js 2.1k Dec 16, 2022
A well documented set of tools for building node web applications.

Perk Framework Perk is a well documented set of tools for building node web applications. The goal of Perk is first and foremost to provide a well doc

Aaron Larner 179 Oct 26, 2022
The Simple, Secure Framework Developers Trust

@hapi/hapi The Simple, Secure Framework Developers Trust Build powerful, scalable applications, with minimal overhead and full out-of-the-box function

hapi.js 14.1k Dec 31, 2022
Build Amazon Simple Queue Service (SQS) based applications without the boilerplate

sqs-consumer Build SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing. Installation

BBC 1.4k Dec 26, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
This web application aim to produce an contest notifier utility and a modern open-source compiler.

This web application aim to produce an contest notifier utility and a modern open-source compiler. The current features of the application include : Code Runner , Upcoming and Ongoing Contests.

ABHAY GUPTA 6 Dec 3, 2022
This script produce the video scroll effect that we can find on the Apple Website's

Scrollable Sequence Description This script produce the video scroll effect that we can find on the Apple Website's. This script is inspired from the

bpy 2 Jan 25, 2022
Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate and produce the video.

?? Introduction Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate

Incredible 113 Dec 6, 2022
A docker image to build a SQS queue listener. Written in TypeScript, made to use with docker.

sqs-request A docker image to build a SQS queue listener. Written in TypeScript, made to use with docker. SQS queue processor with node, ts-squiss, wh

Marcus Yoda 3 Jan 20, 2022
NestJS + AWS SQS sample

nestjs-sqs-sample 概要 NestJS + AWS SQSのサンプルプロジェクトです。 localstackのSQSを使用して動作確認をします。 動作環境 Mac OS Node.js - 16.x yarn - 1.22.x Docker Desktop - 4.2.0以上 AWS

Yasuyuki Saito 8 Oct 18, 2022
awsrun 189 Jan 3, 2023
A chat logs online saver for discord bots to save messages history & cleared messages online

Chat Logs NPM package that saves messages online to view it later Useful for bots where users can save messages history & cleared messages online Supp

TARIQ 8 Dec 28, 2022