【发布时间】:2020-06-16 23:25:35
【问题描述】:
我正在尝试在我的 nestjs 应用程序中使用事件。
但是当我尝试触发命令时,我得到CommandHandlerNotFoundException。
我有message-bus.module:
@Module({
imports: [CqrsModule],
providers: [
MessageBusLocalService,
StartWorkflowHandler
],
exports: [MessageBusLocalService]
})
export class MessageBusModule {
}
message-bus-local.service
@Injectable()
export class MessageBusLocalService {
constructor(private readonly commandBus: CommandBus, private eb: EventBus) {
}
startWorkflow(workflowId: string, payload: any) {
return this.commandBus.execute(
new StartWorkflowCommand(workflowId, payload)
);
}
}
和start-workflow.handler
@CommandHandler(StartWorkflowCommand)
export class StartWorkflowHandler implements ICommandHandler<StartWorkflowCommand> {
constructor() {}
async execute(command: StartWorkflowCommand) {
console.log('Workflow started', command.jobId);
return true;
}
}
我正在尝试在启动应用程序时触发命令:
const app = await NestFactory.create(ApplicationModule);
const service = app.get(MessageBusLocalService);
try {
const c = await service.startWorkflow('abcde', {just: "test"});
console.log('And returned', c);
} catch (e) {
console.error(e)
}
并且...我在那里得到了CommandHandlerNotFoundException,尽管我相信它已被宣布...我做错了什么?
提前致谢。
【问题讨论】: