-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bf838e
commit c0d44f0
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--- | ||
slug: release/3.20.0 | ||
title: Release 3.20.0 | ||
authors: [harry] | ||
tags: [release] | ||
--- | ||
|
||
升级请参考 [如何更新 Midway](/docs/how_to_update_midway) 中描述,请不要单独升级某个组件包。 | ||
|
||
本次 3.20 版本,主要引入了全新的 BullMQ 组件,作为 Bull 组件的升级替代,提供了更好的性能和更多的功能。 | ||
|
||
下面是更为细节的描述。 | ||
|
||
## BullMQ 组件 | ||
|
||
从 v3.20 开始,我们引入了全新的 BullMQ 组件,作为 Bull 组件的下一代实现。BullMQ 提供了更好的性能和更丰富的功能,包括: | ||
|
||
- 更好的类型支持 | ||
- 更强大的任务流(Flow Producer)功能 | ||
- 更完善的事件系统 | ||
- 更灵活的任务处理机制 | ||
|
||
基础使用示例: | ||
|
||
```typescript | ||
// 定义任务处理器 | ||
@Processor('test') | ||
export class TestProcessor implements IProcessor { | ||
async execute(data: any) { | ||
// 处理任务逻辑 | ||
console.log('processing job:', data); | ||
} | ||
} | ||
|
||
// 执行任务 | ||
const testQueue = this.bullmqFramework.getQueue('test'); | ||
await testQueue?.runJob({ | ||
name: 'harry' | ||
}); | ||
``` | ||
|
||
任务流示例: | ||
|
||
```typescript | ||
// 创建任务流 | ||
const flowProducer = bullmqFramework.createFlowProducer({}, 'test-flow'); | ||
|
||
await flowProducer.add({ | ||
name: 'flow-test', | ||
queueName: 'flow-queue-1', | ||
data: { value: 1 }, | ||
children: [ | ||
{ | ||
name: 'child-job', | ||
queueName: 'flow-queue-2', | ||
data: { value: 2 } | ||
} | ||
] | ||
}); | ||
``` | ||
|
||
更多的内容,请参考 [BullMQ 组件文档](/docs/extensions/bullmq)。 | ||
|
||
## Bull 组件迁移提示 | ||
|
||
从 v3.20 开始,我们推荐使用 BullMQ 组件替代原有的 Bull 组件。虽然 Bull 组件仍然可用,但我们建议在新项目中使用 BullMQ,并逐步将现有项目迁移到 BullMQ。 | ||
|
||
主要的变化包括: | ||
|
||
1. 配置方式的调整 | ||
```typescript | ||
// Bull | ||
export default { | ||
bull: { | ||
defaultQueueOptions: { | ||
redis: { | ||
port: 6379, | ||
host: '127.0.0.1', | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
// BullMQ | ||
export default { | ||
bullmq: { | ||
defaultConnection: { | ||
port: 6379, | ||
host: '127.0.0.1', | ||
}, | ||
}, | ||
} | ||
``` | ||
|
||
2. Worker 和事件处理 | ||
```typescript | ||
// BullMQ 新增了独立的 Worker 和 QueueEvents | ||
const worker = bullmqFramework.createWorker( | ||
'queueName', | ||
async (job) => { | ||
// 处理任务 | ||
} | ||
); | ||
|
||
const queueEvents = queue.createQueueEvents(); | ||
queueEvents.on('completed', ({ jobId }) => { | ||
console.log(`Job ${jobId} completed!`); | ||
}); | ||
``` | ||
|
||
3. 任务流支持 | ||
```typescript | ||
// BullMQ 支持创建任务依赖关系 | ||
const flowProducer = bullmqFramework.createFlowProducer(); | ||
await flowProducer.add({ | ||
name: 'flow-test', | ||
queueName: 'flow-queue-1', | ||
children: [/* 子任务 */] | ||
}); | ||
``` | ||
|
||
4. 队列操作的增强 | ||
```typescript | ||
// BullMQ 提供了更多队列操作方法 | ||
const queue = bullmqFramework.createQueue('test'); | ||
await queue.runJob(data); // 执行任务 | ||
await queue.createQueueEvents(); // 创建事件监听 | ||
await queue.createQueueEventsProducer(); // 创建事件生产者 | ||
``` | ||
|
||
## 其他更新 | ||
|
||
* typeorm 组件现在可以指定自定义的 DataSource 了,以支持一些自定义数据源的场景 | ||
* 更新了一些依赖库以提高安全性和稳定性 | ||
|
||
更多的更新内容和详细信息,请参考我们的 [ChangeLog](https://midwayjs.org/changelog/v3.20.0)。 | ||
|