$ show bbc/sqs-consumer
This repository is a mature, well-maintained Node.js library for building SQS-based applications without boilerplate. It provides a `Consumer` class that polls an AWS SQS queue, invokes user-defined message handlers (`handleMessage` or `handleMessageBatch`), and manages the full message lifecycle: receive, process, delete on success, and visibility timeout management. The architecture is a single class extending a typed `EventEmitter`, emitting events for lifecycle hooks (started, stopped, message_received, message_processed, error, etc.). Key entry points are `Consumer.create(options)`, `consumer.start()`, and `consumer.stop()`. The library supports both single and batch message processing, configurable polling intervals, heartbeat extensions for long-running handlers, graceful shutdown with in-flight message completion, and FIFO queue warnings. External dependencies are minimal: `@aws-sdk/client-sqs` for AWS SDK v3 and `debug` for logging. The codebase is written in TypeScript, fully tested with unit and integration tests, and follows semantic versioning with automated releases via semantic-release.
The LLM identified 2 files worth highlighting for reuse:
A typed EventEmitter that automatically appends queue metadata (queueUrl) to every emitted event. It overrides `on`, `once`, and `emit` to enforce type safety for the library's event map and to inject a `QueueMetadata` object as the last argument to listeners. This pattern is reusable in any event-driven system that needs consistent metadata enrichment without burdening callers.
Defines three custom error classes (SQSError, TimeoutError, StandardError) and helper functions (toSQSError, toStandardError, toTimeoutError) for consistent error creation and enrichment. The SQSError class captures AWS error details (code, statusCode, retryable, service, fault) and optionally extended response/metadata. The helpers also attach messageIds and queueUrl for traceability. This pattern is reusable in any AWS SDK integration requiring structured error handling.