
MessageQueueServiceBase 的队列类。
当前,我们仅支持使用 bull-mqbull-mq 作为队列驱动。
创建和使用新队列的步骤
- 在枚举
MESSAGE_QUEUES下为您的新队列添加队列名称。 - 提供以队列名称为依赖令牌的队列工厂实现。
- 在所需模块/服务中以队列名称作为依赖令牌注入您创建的队列。
- 添加与生产者相同令牌注入的工作类。

MessageQueueServiceBase 的队列类。
当前,我们仅支持使用 bull-mqbull-mq 作为队列驱动。
MESSAGE_QUEUES 下为您的新队列添加队列名称。class Resolver {
constructor(@Inject(MESSAGE_QUEUES.custom) private queue: MessageQueueService) {}
async onSomeAction() {
//business logic
await this.queue.add(someData);
}
}
//async worker
class CustomWorker {
constructor(@Inject(MESSAGE_QUEUES.custom) private queue: MessageQueueService) {
this.initWorker();
}
async initWorker() {
await this.queue.work(async ({ id, data }) => {
//worker logic
});
}
}
此页面对您有帮助吗?