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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fgiova/sqs-consumer

v1.0.0

Published

[![NPM version](https://img.shields.io/npm/v/@fgiova/mini-sqs-client.svg?style=flat)](https://www.npmjs.com/package/@fgiova/sqs-consumer) ![CI workflow](https://github.com/fgiova/sqs-consumer/actions/workflows/node.js.yml/badge.svg) [![TypeScript](https:/

Downloads

2

Readme

SQS consumer using undici

NPM version CI workflow TypeScript Maintainability Test Coverage

Description

This module allows consuming SQS messages using @fgiova/mini-sqs-client thorough the aws-json protocol with "undici" as http agent . The @fgiova/aws-signature module is used for signing requests to optimize performance.

Installation

npm install @fgiova/sqs-consumer

Usage

import {SQSConsumer} from '@fgiova/sqs-consumer'

const consumer = new SQSConsumer({
    queueARN: "arn:aws:sqs:eu-central-1:000000000000:test-queue-hooks",
    handler: async (message) => {
        console.log(message.Body);
    }
});

Options

| Option | Type | Default | Description | |-----------------|-------------------------------------|---------|----------------------------------------------------| | queueARN | string | | The ARN of the queue to consume | | handler | (message: Message) => Promise | | The handler function to be called for each message | | logger | Logger | console | The logger to be used | | autoStart | boolean | true | Whether to start the consumer automatically | | handlerOptions | HandlerOptions | | The options for the handler | | clientOptions | ClientOptions | | The options for the client | | consumerOptions | ConsumerOptions | | The options for the consumer | | hooks | Hooks | | The hooks to be called on specific events |

HandlerOptions

| Option | Type | Default | Description | |-------------------|---------|---------|----------------------------------------------------------------------------------------------------------| | deleteMessage | boolean | true | Whether to delete the message after handling (if handler execute without any error) | | extendVisibility | boolean | true | Whether to extend the visibility timeout during message handling | | excuteTimeout | number | 30000 | The timeout for the handler execution in ms | | parallelExecution | boolean | true | If true execute handler in parallel for each batch of messages received, otherwise execute consecutively |

ClientOptions

| Option | Type | Default | Description | |------------------|------------------------|---------|-----------------------------------------------------------------------------------------------------------| | sqsClient | MiniSQSClient | | The MiniSQSClient client to be used. If not provided, a new client will be created using the queueARN. | | endpoint | string | | The endpoint to be used for the client. If not provided, the endpoint will be inferred from the queueARN. | | undiciOptions | Pool.Options | | The options for the undici client. | | signer | Signer / SignerOptions | | The signer to be used for signing requests. If not provided, a new singleton signer will be created. | | destroySigner | boolean | false | Whether to destroy the signer when the consumer is destroyed. |

ConsumerOptions

| Option | Type | Default | Description | |-------------------------|----------|---------|------------------------------------------------------------| | visibilityTimeout | number | 30 | The visibility timeout for the messages in seconds | | waitTimeSeconds | number | 20 | The wait time for the receiveMessage call in seconds | | itemsPerRequest | number | 10 | The maximum number of messages to be received at once | | messageAttributeNames | string[] | [] | The message attribute names to be included in the response |

Hooks

| 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 |

API

SQSConsumer(options: SQSConsumerOptions)
SQSConsumer.start(): Promise<void>
SQSConsumer.stop(destroyConsumer = false): Promise<void>
SQSConsumer.addHook(hookname: string, func: Function): void

License

Licensed under MIT.