npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fgiova/fastify-sqs-consumer

v2.0.1

Published

sqs-consumer fastify plugin

Downloads

493

Readme

fastify sqs-consumer

NPM version CI workflow TypeScript Linted with Biome Maintainability Code Coverage

Description

This plugin for fastify 5.x (for fastify 4.x use 1.x ver) allows you to consume messages from AWS SQS queues. On fastify shutdown a simple wait function is called to wait for the end of the processing of the messages in progress.

Warning To use this plugin, you must have correctly configured your AWS credentials. This plugin uses @fgiova/mini-sqs-client and @fgiova/sqs-consumer to interact with SQS service.

Install

npm i @fgiova/fastify-sqs-consumer

Usage

const fastify = require("fastify")()

fastify.register(require("fastify-sqs-consumer"), [
    {
        arn: "arn:aws:sqs:eu-central-1:000000000000:MyQueue",
        waitTimeSeconds: 20,
        timeout: 10_000,
        batchSize: 10,
        handlerFunction: async (message, fastify) => {
            return true;
        }
    }
]);

Options

Options are an array of objects with the following properties (one more for each queue):

| Option | Type | Description | |-----------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | arn* | string | The ARN of the Amazon SQS queue from which messages are received. | | handlerFunction* | function | The function that will be called for each message. | | name | string | An optional name for the consumer (useful for add hooks post config). If not provided, uuid is assigned. | | waitTimeSeconds | number | The duration (in seconds, default 20s) for which the call waits for a message to arrive in the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call returns successfully with an empty list of messages. | | timeout | number | The duration before the message is considered as failed: default 90000ms. | | batchSize | number | The maximum number of messages to return. Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values: 1 to 10. Default: 1. | | messageAttributeNames | string[] | Array of caught message's attributes for each message | | events | object | Events functions for the consumer (detail in next table) | | sqs | SQSClient | Initialized SQS Client (useful for testing sessions) |

  • required

handlerFunction

Handler function is an async function called for each message received from the queue. Each Error thrown by the function is caught and the message is not deleted from the queue. Otherwise, the message is deleted from the queue.

Events

| Option | Type | Description | |------------------|-----------------------------------------------------------------------|---------------------------------------------------------------------| | onPoll | (messages: Message[]) => Promise<Message[]> | Called when the consumer polls for messages | | onMessage | (message: Message) => Promise | Called when the consumer receives a message | | onHandle | (message: Message) => Promise | Called when the consumer handles a message | | onHandlerSuccess | (message: Message) => Promise | Called when the consumer handles a message successfully | | onHandlerTimeout | (message: Message) => Promise | Called when the consumer handler execution exceed executionTimeout | | onHandlerError | (message: Message, error: Error) => Promise | Called when the consumer handler execution throws an error | | onSuccess | (message: Message) => Promise | Called when the consumer handler execution finishes successfully | | onError | ( hook: HookName, message: Message, error: Error) => Promise | Called when the consumer handler execution throws an uncaught error | | onSQSError | (error: Error, message?: Message) => Promise | Called when the consumer receives an error from the SQS service |

License

Licensed under MIT.