Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sqs-consumer

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqs-consumer

Build SQS-based Node applications without the boilerplate

  • 8.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is sqs-consumer?

The sqs-consumer npm package is a simple to use library for building Amazon Simple Queue Service (SQS) based applications. It allows you to create consumers that process messages from SQS queues with ease, handling message polling, error handling, and visibility timeout extensions.

What are sqs-consumer's main functionalities?

Creating a Consumer

This code sample demonstrates how to create a basic consumer that reads messages from an SQS queue and logs the message body to the console.

const { Consumer } = require('sqs-consumer');
const AWS = require('aws-sdk');

const app = Consumer.create({
  queueUrl: 'https://sqs.us-east-1.amazonaws.com/account-id/queue-name',
  handleMessage: async (message) => {
    console.log(message.Body);
  },
  sqs: new AWS.SQS()
});

app.on('error', (err) => {
  console.error(err.message);
});

app.start();

Error Handling

This code sample shows how to handle errors that occur during message processing. The 'error' event is emitted for general errors, while the 'processing_error' event is specifically for errors that occur during message handling.

const { Consumer } = require('sqs-consumer');
const AWS = require('aws-sdk');

const app = Consumer.create({
  queueUrl: 'https://sqs.us-east-1.amazonaws.com/account-id/queue-name',
  handleMessage: async (message) => {
    throw new Error('Processing error');
  },
  sqs: new AWS.SQS()
});

app.on('error', (err) => {
  console.error('Error occurred:', err.message);
});

app.on('processing_error', (err) => {
  console.error('Processing error:', err.message);
});

app.start();

Batch Processing

This code sample demonstrates how to process messages in batches. The 'handleMessageBatch' function receives an array of messages, allowing for more efficient processing.

const { Consumer } = require('sqs-consumer');
const AWS = require('aws-sdk');

const app = Consumer.create({
  queueUrl: 'https://sqs.us-east-1.amazonaws.com/account-id/queue-name',
  handleMessageBatch: async (messages) => {
    messages.forEach(message => console.log(message.Body));
  },
  sqs: new AWS.SQS()
});

app.on('error', (err) => {
  console.error(err.message);
});

app.start();

Other packages similar to sqs-consumer

Keywords

FAQs

Package last updated on 15 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc