我正在按照文档开始使用队列。我安装了@nestjs/bull, bull,@types/bull依赖项。这是我的app.module.ts:
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
BullModule.registerQueue({
name: 'create_checkin',
redis: {
host: 'localhost',
port: 6379,
},
}),
EventModule,
],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
我在根模块中导入了 BullModule。这是我的event.service.ts:
@Injectable()
export class EventService {
constructor(
@InjectQueue('create_checkin') private readonly createCheckinQueue: Queue,
) {
}
}
Run Code Online (Sandbox Code Playgroud)
当我启动服务器时,我收到以下错误消息:
Nest can't resolve dependencies of the EventService
Please make sure that the argument BullQueue_create_checkin at index [0] is available in the EventModule context.
Run Code Online (Sandbox Code Playgroud)
我不知道我哪一步做错了。有人可以帮助我吗?
Hel*_*man 13
BullModule有类似的问题,在我的情况下,将其添加到exports数组中以便成功运行整个项目就足够了。像这样:
@Module({\n imports: [\n BullModule.registerQueue({ ... }),\n ...\n ],\n ...\n exports: [\n BullModule, // <\xe2\x80\x94 this is important!\n ...\n ]\n})\nRun Code Online (Sandbox Code Playgroud)\n然后在我的服务中我已经能够注入队列:
\n@InjectQueue(\'print\') private queue: Queue<PrintJob>\nRun Code Online (Sandbox Code Playgroud)\n
小智 0
确保将 EventService 放置在 EventModule 中的providers 数组下。
@Module({
providers: [EventService],
controllers :[],
imports: [YOUR_MODULES],
exports: [EventService]
})
export class EventModule {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7151 次 |
| 最近记录: |