### Install sqs-producer Package Source: https://github.com/bbc/sqs-producer/blob/main/README.md Install the sqs-producer package using npm. ```bash npm install sqs-producer ``` -------------------------------- ### Create and Use Basic SQS Producer Source: https://github.com/bbc/sqs-producer/blob/main/README.md Create a simple SQS producer and send messages. Requires importing Producer and SQSClient. Ensure AWS credentials are configured. ```javascript import { Producer } from "sqs-producer"; import { SQSClient } from "@aws-sdk/client-sqs"; // create simple producer const producer = Producer.create({ queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name", region: "eu-west-1", }); // send messages to the queue await producer.send(["msg1", "msg2"]); // get the current size of the queue const size = await producer.queueSize(); console.log(`There are ${size} messages on the queue.`); // send a message to the queue with a specific ID (by default the body is used as the ID) await producer.send([ { id: "id1", body: "Hello world", }, ]); // send a message to the queue with // - delaySeconds (must be an number contained within 0 and 900) // - messageAttributes await producer.send([ { id: "id1", body: "Hello world with two string attributes: attr1 and attr2", messageAttributes: { attr1: { DataType: "String", StringValue: "stringValue" }, attr2: { DataType: "Binary", BinaryValue: new Buffer("binaryValue") }, }, }, { id: "id2", body: "Hello world delayed by 5 seconds", delaySeconds: 5, }, ]); // send a message to a FIFO queue // // note that AWS FIFO queues require two additional params: // - groupId (string) // - deduplicationId (string) // // deduplicationId can be excluded if content-based deduplication is enabled // // https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queue-recommendations.html await producer.send({ id: "testId", body: "Hello world from our FIFO queue!", groupId: "group1234", deduplicationId: "abcdef123456", // typically a hash of the message body }); // send messages to a standard queue with groupId for fair queue behavior // // Fair queues automatically mitigate noisy neighbor impact in multi-tenant queues // by using groupId to identify tenants and ensure fair resource allocation // // https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fair-queues.html await producer.send([ { id: "msg1", body: "Message from tenant A", groupId: "tenant-a", }, { id: "msg2", body: "Message from tenant B", groupId: "tenant-b", }, ]); ``` -------------------------------- ### Run SQS Producer Tests Source: https://github.com/bbc/sqs-producer/blob/main/README.md Execute the test suite for the sqs-producer package using npm. ```bash npm test ``` -------------------------------- ### Configure SQS Producer with Custom SQS Client Source: https://github.com/bbc/sqs-producer/blob/main/README.md Create an SQS producer with a pre-configured SQS client, allowing manual specification of credentials and region. This is an alternative to using environment variables for AWS credentials. ```javascript import { Producer } from "sqs-producer"; import { SQSClient } from "@aws-sdk/client-sqs"; // create simple producer const producer = Producer.create({ queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name", region: "eu-west-1", sqs: new SQSClient({ region: "my-region", credentials: { accessKeyId: "yourAccessKey", secretAccessKey: "yourSecret", }, }), }); // send messages to the queue await producer.send(["msg1", "msg2"]); ``` -------------------------------- ### Generate SQS Producer Coverage Report Source: https://github.com/bbc/sqs-producer/blob/main/README.md Generate a code coverage report for the sqs-producer package by running the specified npm command. ```bash npm run coverage ``` -------------------------------- ### Lint SQS Producer Code Source: https://github.com/bbc/sqs-producer/blob/main/README.md Check the sqs-producer code for potential problems using ESLint with the provided npm command. ```bash npm run lint ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.