nestjs - NestJS - 无法解析队列?
问题描述
我正在关注文档以开始使用队列。我安装了@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 {}
我在根模块中导入了 BullModule。这是我的event.service.ts
:
@Injectable()
export class EventService {
constructor(
@InjectQueue('create_checkin') private readonly createCheckinQueue: Queue,
) {
}
}
当我启动服务器时,我收到以下错误消息:
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.
我不知道我做错了哪一步。有人可以帮助我吗?
解决方案
BullModule
有一个类似的问题,在我的情况下,将它添加到数组中就足够了exports
,以便成功运行整个项目。像这样:
@Module({
imports: [
BullModule.registerQueue({ ... }),
...
],
...
exports: [
BullModule, // <— this is important!
...
]
})
然后在我的服务中,我已经能够注入队列:
@InjectQueue('print') private queue: Queue<PrintJob>
推荐阅读
- gradle - 如何使用一个名称引用多个任务的输出?
- spring - Spring XML 配置文件未加载到 Spring Boot 中
- batch-file - 如何将参数传递给运行带有这些参数的应用程序的批处理文件?
- javascript - 地图控制在 JSFiddle 中有效,但在网络服务器上无效
- performance - Opengl 性能改进 glTexSubImage2D 函数
- java - 即使活动和应用程序被破坏,如何继续上传任务?
- javascript - 使用 Cypress.io 捕获所有 XHR 请求
- r - 如何将一些行放在一起?
- c#-7.0 - 找不到 sgfplib.dll
- java - Hibernate @OneToMany 不保存外键