NestJS - pub/sub 微服务模式
NestJS - pub/sub pattern in microservices
有没有办法通过 pub/sub 模式使用 NestJS 微服务?例如用amqp?据我了解,每个 'microservice type' 都遵循请求/响应模式。
@EventPattern('user_created')
async handleUserCreated(data: Record<string, unknown>) {
// business logic
}
async publish() {
this.client.emit<number>('user_created', new UserCreatedEvent());
}
以上解决方案无效。
看这里
https://github.com/nestjs/nest/issues/3981
根据 NestJs 文档,您有两个选择。
- 使用 Redis 或 NATS 作为传输器。
或
- 创建您自己的交通工具https://github.com/nestjs/docs.nestjs.com/issues/113
有没有办法通过 pub/sub 模式使用 NestJS 微服务?例如用amqp?据我了解,每个 'microservice type' 都遵循请求/响应模式。
@EventPattern('user_created')
async handleUserCreated(data: Record<string, unknown>) {
// business logic
}
async publish() {
this.client.emit<number>('user_created', new UserCreatedEvent());
}
以上解决方案无效。 看这里 https://github.com/nestjs/nest/issues/3981
根据 NestJs 文档,您有两个选择。
- 使用 Redis 或 NATS 作为传输器。 或
- 创建您自己的交通工具https://github.com/nestjs/docs.nestjs.com/issues/113