简体   繁体   中英

NestJS - pub/sub pattern in microservices

Is there a way to use NestJS microservices with the pub/sub pattern? For example with amqp? As far as I understand, every 'microservice type' is following the request / response pattern.

@EventPattern('user_created')
async handleUserCreated(data: Record<string, unknown>) {
  // business logic
}
async publish() {
  this.client.emit<number>('user_created', new UserCreatedEvent());
}

https://docs.nestjs.com/microservices

The above solution does not work. See here https://github.com/nestjs/nest/issues/3981

As per the NestJs documentation, you have two options.

  1. Either use Redis or NATS as a transporter. or
  2. Create your own transport https://github.com/nestjs/docs.nestjs.com/issues/113

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM