Registry / messaging / sqs-producer

sqs-producer

JSON →
library9.0.5jsnpmunverified

sqs-producer is a Node.js library for enqueuing messages onto Amazon SQS queues. Current stable version is 9.0.5, requiring Node >=22. It is a peer dependency of @aws-sdk/client-sqs v3.1036+. The library provides a simple Producer class that handles batching, message formatting, and queue size retrieval. It natively supports both standard and FIFO queues, including groupId/deduplicationId for FIFO and fair queue behavior for multi-tenant scenarios. Ships TypeScript definitions, ESM-only (no CJS), and is maintained by BBC. Differentiators: minimal API surface, no native dependencies, explicit FIFO support, and fair queue integration.

npm install sqs-producer
INSTALL
IMPORT
SIG · SQS-PRODUCER
S
sqs-producer
messagingjavascriptv9.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Producer
import { Producer } from 'sqs-producer'
const Producer = require('sqs-producer')
ESM-only package; cannot use require(). Must use named import.
SQSProducer
import { Producer } from 'sqs-producer'
import SQSProducer from 'sqs-producer'
No default export. The class is exported as named export Producer. In v8 and earlier, default export existed, but as of v9 it is ESM-only with named export.
Producer.create
Producer.create({ queueUrl, region })
new Producer({ queueUrl, region })
Use static factory method create() rather than constructor; the constructor is not publicly documented.

Basic producer creation and message sending with SQS, including single, batch, and attribute-enriched messages.

import { Producer } from 'sqs-producer'; import { SQSClient } from '@aws-sdk/client-sqs'; const producer = Producer.create({ queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue', region: 'us-east-1', }); // Send a single message await producer.send('Hello world'); // Send multiple messages await producer.send(['msg1', 'msg2']); // Send with custom id and attributes await producer.send({ id: 'my-id', body: 'Important message', messageAttributes: { priority: { DataType: 'String', StringValue: 'high' } } }); // Get current queue size const size = await producer.queueSize(); console.log(`Queue size: ${size}`);
Debug
Known issues
breakingVersion 9.0+ is ESM-only. require() will throw ERR_REQUIRE_ESM.
fix
Switch to import syntax. If you must use require, use dynamic import or stay on v8.x.
affects: >=9.0.0
breakingNode.js >=22 required as of v9.0.0. Older Node versions are unsupported.
fix
Upgrade Node.js to v22 or later, or use an older version of sqs-producer that supports your Node version.
affects: >=9.0.0
gotchaThe package does not automatically retry on SQS errors. Network failures or throttling can cause send() to throw.
fix
Wrap send() calls in try/catch and implement exponential backoff/retry logic in your application.
affects: >=1.0.0
gotchaFor FIFO queues, groupId and deduplicationId are required unless content-based deduplication is enabled. Missing these will cause SQS errors.
fix
Ensure that every message sent to a FIFO queue includes groupId and deduplicationId (or enable content-based deduplication on the queue).
affects: >=1.0.0
deprecatedConstructor new Producer() is not part of the public API; use Producer.create() instead.
fix
Replace new Producer(options) with Producer.create(options).
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/sqs-producer/index.mjs not supported.
Using require() on a v9+ ESM-only package.
fix
Convert to ES module (add "type": "module" in package.json) and use import { Producer } from 'sqs-producer'. Alternatively, use dynamic import: const { Producer } = await import('sqs-producer');
TypeError: Producer.create is not a function
Using default import instead of named import, e.g., import Producer from 'sqs-producer'.
fix
Use named import: import { Producer } from 'sqs-producer';
The groupId and deduplicationId must be specified for FIFO queues
Trying to send a message to a FIFO queue without required FIFO fields.
fix
Add groupId and deduplicationId to each message object. For example: { id: '1', body: 'msg', groupId: 'group1', deduplicationId: 'hash1' }.
ValidationError: The request must contain the parameter MessageBody
Sending a message object that has no body property.
fix
Ensure each message object has a body field. For string messages, the body is the string itself. For objects, provide body: 'your message'.
Upgrade
Version history
9.0.5latest on npm
Audit
Dependencies
@aws-sdk/client-sqsrequiredPeer dependency: provides the SQS client used internally by the producer.
Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
sqs-producer — npm install sqs-producer · libregistry