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

@vercel/sqs-consumer

Package Overview
Dependencies
Maintainers
10
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/sqs-consumer

Build SQS-based Node applications without the boilerplate

  • 5.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
421K
increased by195.06%
Maintainers
10
Weekly downloads
 
Created

What is @vercel/sqs-consumer?

@vercel/sqs-consumer is a Node.js library that simplifies the process of consuming messages from Amazon SQS (Simple Queue Service). It provides a high-level API to handle message processing, error handling, and visibility timeout management, making it easier to build robust and scalable applications that interact with SQS.

What are @vercel/sqs-consumer's main functionalities?

Creating a Consumer

This feature allows you to create a consumer that listens to an SQS queue and processes messages. The `handleMessage` function is where you define the logic for handling each message.

const { Consumer } = require('@vercel/sqs-consumer');

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

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

app.start();

Error Handling

This feature demonstrates how to handle errors that occur during message processing. The `error` event is emitted for general errors, while the `processing_error` event is specific to errors that occur within the `handleMessage` function.

const { Consumer } = require('@vercel/sqs-consumer');

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

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

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

app.start();

Batch Processing

This feature allows you to process messages in batches, which can be more efficient for high-throughput applications. The `handleMessageBatch` function is used to define the logic for handling a batch of messages.

const { Consumer } = require('@vercel/sqs-consumer');

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

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

app.start();

Other packages similar to @vercel/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