# nest-bull-delay-queue **Repository Path**: DaFengChe856/nest-bull-delay-queue ## Basic Information - **Project Name**: nest-bull-delay-queue - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-16 - **Last Updated**: 2026-03-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Nest.js Bull 延迟消息队列 基于 Nest.js + TypeScript + Bull.js + Redis 实现的延迟消息队列演示项目。 ## 功能特性 - 延迟任务 - 指定时间后执行 - 定时任务 - 在指定时间点执行 - 重复任务 - 支持 Cron 表达式或固定间隔 - 失败重试 - 自动指数退避重试 - 队列监控 - Bull Board UI 可视化 ## 技术栈 - Nest.js ^11 - Bull.js ^4.16 - @nestjs/bull ^11.0 - Redis ## 快速开始 ### 安装依赖 ```bash pnpm install ``` ### 配置 Redis 在 `src/queue/queue.module.ts` 中配置 Redis 连接: ```typescript BullModule.forRoot({ redis: { host: 'your-redis-host', port: 6379, username: 'your-username', password: 'your-password', }, }), ``` ### 启动项目 ```bash # 开发模式(热重载) pnpm run start:dev # 生产模式 pnpm run build pnpm run start:prod ``` 服务启动后访问 `http://localhost:3000` ## API 接口 | 方法 | 路径 | 说明 | 示例 | |------|------|------|------| | POST | `/queue/delay` | 添加延迟任务 | `{"message": "test", "delay": 5000}` | | POST | `/queue/scheduled` | 添加定时任务 | `{"message": "test", "timestamp": 1742150400000}` | | POST | `/queue/repeat` | 添加重复任务 | `{"message": "test", "every": 5000}` | | GET | `/queue/stats` | 获取队列状态 | - | | GET | `/queue/waiting` | 获取等待中的任务 | - | | DELETE | `/queue/empty` | 清空队列 | `{"queue": "delay-queue"}` | | GET | `/queue/health` | 健康检查 | - | ### 请求示例 ```bash # 添加 5 秒延迟任务 curl -X POST http://localhost:3000/queue/delay \ -H "Content-Type: application/json" \ -d '{"message": "测试消息", "delay": 5000}' # 添加重复任务(每 5 秒执行,最多 10 次) curl -X POST http://localhost:3000/queue/repeat \ -H "Content-Type: application/json" \ -d '{"message": "定时任务", "every": 5000, "limit": 10}' # 获取队列状态 curl http://localhost:3000/queue/stats ``` ## 项目结构 ``` src/ ├── main.ts # 入口文件 ├── app.module.ts # 根模块 └── queue/ ├── queue.module.ts # Queue 模块(Redis 配置) ├── queue.service.ts # 队列服务 ├── queue.controller.ts # API 控制器 ├── queue.processor.ts # 延迟队列处理器 └── cron-queue.processor.ts # 定时队列处理器 ``` ## 许可证 MIT License - 查看 [LICENSE](LICENSE) 文件