🦅 NestJS Intermediate

What are NestJS microservices and what transports are supported?

Answer

NestJS has first-class support for microservices through the @nestjs/microservices package. A microservice is created with NestFactory.createMicroservice() instead of the regular create(). Supported transports: TCP (simple, built-in), Redis (pub/sub), NATS, RabbitMQ, Kafka, gRPC, MQTT. Message handlers use @MessagePattern() or @EventPattern() decorators instead of HTTP method decorators. Services communicate by injecting a ClientProxy and using client.send(pattern, data) (request-response) or client.emit(pattern, data) (fire-and-forget). NestJS microservices abstract away transport details so you can switch transports with minimal code changes.