bbc/sqs-consumer — dự án backend — đang có 1.9k sao GitHub trong nhóm Backend. Build Amazon Simple Queue Service (SQS) based applications without the boilerplate
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Build SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing.
Installation
To install this package, simply enter the following command into your terminal (or the variant of whatever package manager you are using):
npm install sqs-consumer
If you would like to use JSR instead, you can find the package here.
Node version
We will only support Node versions that are actively or security supported by the Node team. You can find the list of versions that are actively supported here.
Documentation
Visit https://bbc.github.io/sqs-consumer/ for the full API documentation.
Usage
import { Consumer } from "sqs-consumer";
const app = Consumer.create({
queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name",
handleMessage: async (message) => {
// do some work with `message`
},
});
app.on("error", (err) => {
console.error(err.message);
});
app.on("processing_error", (err) => {
console.error(err.message);
});
app.start();
Polling Behavior: The queue is polled continuously for messages using long polling.
Message Processing Behavior: By default messages are processed one at a time – a new message won't be received until the first one has been processed. To process messages in parallel, use the batchSize option detailed here.
It's also important to await any processing that you are doing to ensure that messages are processed one at a time.
Message Acknowledgment Behavior:
When alwaysAcknowledge is false (the default)
Returning undefined, an empty object {}, or an empty array []: Message(s) will NOT be deleted (left on queue for retry)
For batch processing, return undefined or [] to prevent acknowledgment of all messages.
For single message handling, return undefined or {} to prevent acknowledgment.
Returning the message object (or an array of messages in batch processing): Message(s) will be acknowledged and deleted
Important: Only the message id(s) that are returned will be deleted.
Returning void is discouraged and will be deprecated in a future release.
When strictReturn is true: Returning null will throw an error. This will be the default behavior in a future release.
When alwaysAcknowledge is true: All messages will be acknowledged and deleted regardless of return value.
Error Handling: Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An SQS redrive policy can be used to move messages that cannot be processed to a dead letter queue.
Deletion Process Messages are deleted from the queue once the handler function has completed successfully (the above items should also be taken into account).
FIFO Queue Support
When using SQS Consumer with FIFO (First-In-First-Out) queues, you might see a warning message in your logs.
As mentioned in the warning, we do not explicitly test SQS Consumer with FIFO queues, this means that we cannot guarantee that the library will work as expected, however, with the correct configuration, it should. If you have done that and believe FIFO to be working as expected, you can suppress the warning by setting suppressFifoWarning: true.
To note: In order to maintain FIFO ordering, you should always use the handleMessageBatch method instead of handleMessage.
Credentials
By default the consumer will look for AWS credentials in the places specified by the AWS SDK. The simplest option is to export your credentials as environment variables:
Consumer will receive and delete messages from the SQS queue. Ensure sqs:ReceiveMessage, sqs:DeleteMessage, sqs:DeleteMessageBatch, sqs:ChangeMessageVisibility and sqs:ChangeMessageVisibilityBatch access is granted on the queue being consumed.
API
Consumer.create(options)
Creates a new SQS consumer using the defined options.
consumer.start()
Start polling the queue for messages.
consumer.stop(options)
Stop polling the queue for messages. You can find the options definition here.
By default, the value of abort is set to false which means pre existing requests to AWS SQS will still be made until they have concluded. If you would like to abort these requests instead, pass the abort value as true, like so:
consumer.stop({ abort: true })
Graceful shutdowns
Calling consumer.stop() on its own only prevents new polls from being scheduled. The consumer will emit stopped immediately, even if the current long poll or message handler is still running. To wait for the final poll plus any in-flight message processing to finish, set pollingCompleteWaitTimeMs to the maximum amount of time you are willing to wait.
While waiting, the consumer emits waiting_for_polling_to_complete every second.
If the timeout elapses first, waiting_for_polling_to_complete_timeout_exceeded fires right before stopped.
For graceful shutdowns keep abort: false (the default). Passing abort: true cancels the shared AbortController, which halts heartbeat extensions and prevents acknowledgements/deletions from finishing.
Here's an example of a graceful shutdown implementation:
bbc/sqs-consumer có 1.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/bbc/sqs-consumer. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
bbc/sqs-consumer có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho bbc/sqs-consumer. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
bbc/sqs-consumer còn đang phát triển không?
Commit gần nhất trên bbc/sqs-consumer là 3 tháng trước (theo timestamp GitHub). Repo có 335 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
bbc/sqs-consumer là gì?
bbc/sqs-consumer (bbc/sqs-consumer) là dự án TypeScript trên GitHub. Theo mô tả gốc: Build Amazon Simple Queue Service (SQS) based applications without the boilerplate
bbc/sqs-consumer so với các dự án Backend khác thế nào?
bbc/sqs-consumer được TopGit xếp vào nhóm Backend, với 1.9k sao GitHub và viết bằng TypeScript. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc thêm về bbc/sqs-consumer ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/bbc/sqs-consumer là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về sqs-consumer?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về sqs-consumer.