# @efebia/sqs-queue-v3 中文文档

规范地址：https://npmcn.com/package/%40efebia/sqs-queue-v3/

版本：0\.0\.10
npm 元数据更新时间：2026-11-12T13:25:05.575Z
中文译文更新时间：2026-11-13T21:34:06.625Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40efebia/sqs-queue-v3
原文对照：https://npmcn.com/package/%40efebia/sqs-queue-v3/?lang=original
项目主页：https://github.com/efebia-com/be-libs#readme
源码仓库：https://github.com/efebia-com/be-libs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：7.4 kB，4 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：2 个
- 首次发布：2023-01-12T18:34:11.545Z
- 最新版本发布：2026-11-12T13:25:05.082Z
- 近 30 天下载量：3044（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 2 个）

## 中文简介

AWS SQS 队列消费者基于 `@efebia/queue`,使用现代模块化 AWS SDK v3(`@aws-sdk/client-sqs`) (中文(简体) ).

## 安装

```sh
npm install @efebia/sqs-queue-v3
```

也可以使用：`pnpm add @efebia/sqs-queue-v3`、`yarn add @efebia/sqs-queue-v3`、`bun add @efebia/sqs-queue-v3`

## README

# @efebia/sqs-queue-v3 (英语)

AWS SQS 队列消费者基于 `@efebia/queue`,使用现代模块化 AWS SDK v3(`@aws-sdk/client-sqs`) (中文(简体) ).

## 安装

```bash
npm install @efebia/sqs-queue-v3
```

## 使用量

```ts
import { SQSClient } from '@aws-sdk/client-sqs';
import { Queue } from '@efebia/sqs-queue-v3';

type MyMessage = { userId: string; action: string };

const client = new SQSClient({ region: 'eu-west-1' });

const queue = new Queue<MyMessage>({
  client,
  receiveOptions: {
    QueueUrl: 'https://sqs.eu-west-1.amazonaws.com/123456789/my-queue',
    WaitTimeSeconds: 20,
    MaxNumberOfMessages: 1,
  },
  sleepTimeout: 5000,
  logger: (obj, msg) => console.log(msg, obj),
});

// Start consuming
queue.start(async (name, params, state) => {
  console.log(`Received "${name}":`, params);
  // set state.del = false to leave the message in the queue
});

// Send a message
await queue.send({ name: 'doWork', params: { userId: '42', action: 'sync' } });

// Stop the loop
queue.stop();
```

## API 密码

### `new Queue<TMessage>(options)`

| 选项 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| `client` | `SQSClient` | —— 说 | **要求.** 配置 `@aws-sdk/client-sqs` 客户端实例 |
| `receiveOptions` | `ReceiveMessageCommandInput` | —— 说 | **要求.** 传到 `ReceiveMessageCommand`。必须包括 `QueueUrl`。 。 。 . |
| `receiveOptions.WaitTimeSeconds` | `number` | `20` | 漫长的等待时间 |
| `receiveOptions.MaxNumberOfMessages` | `number` | `1` | 每个收件者的最大消息 |
| `canRead` | `() => boolean | Promise<boolean>` | `() => true` | 在每次收到之前拨打; 返回 `false` 跳过迭代 |
| `logger` | `(obj, msg?) => void` | 无 -op | 错误和警告的日志函数 |
| `sleepTimeout` | `number` | `5000` | 在重试前等待出错 |
| `errorCallback` | `(error) => void` | `console.error` | 调用循环中未发现的错误 |

### 继承自 `@efebia/queue`

-   `start(callback, canThrow?)` 开始投票循环
-   `stop()` 信号循环停止
-   `resume(callback)` ——重新启动已停止的队列
-   `isRunning()` ——返回 `true` 如果循环活动
-   `send(message)` - 发送信息(添加) `createdAt` 自动)

**回调签名 :**

```ts
(name: string, params: TMessage, state: { del: boolean }) => void | Promise<void>
```

回调解析后,除非 `state.del` 设置为 `false`。 。 。 .

## 许可证

麻省理工学院

## 常见问题

### @efebia/sqs-queue-v3 是什么？

AWS SQS 队列消费者基于 @efebia/queue,使用现代模块化 AWS SDK v3\(@aws-sdk/client-sqs\) \(中文\(简体\) \)\.

### 如何安装 @efebia/sqs-queue-v3？

在项目目录运行 npm install @efebia/sqs-queue-v3，或使用 pnpm add / yarn add / bun add。

### @efebia/sqs-queue-v3 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/efebia\_\_sqs-queue-v3 是否存在。

### @efebia/sqs-queue-v3 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @efebia/sqs-queue-v3 可以商用吗？

@efebia/sqs-queue-v3 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @efebia/sqs-queue-v3 的下载量有多少？

根据 npm 官方下载统计，@efebia/sqs-queue-v3 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,044 次，日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @efebia/sqs-queue-v3 还在维护吗？

最新版本 0\.0\.10 发布于 2026/11/12（1 天前）；至今共发布 10 个版本，其中过去 12 个月发布了 2 个；首次发布于 2023/01/13。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

