Search code examples
node.jsamqpnestjs

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.


Solution

  • @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