Your first microservice — Microservices · NestJS

Split the cats API in two: a cats service that answers messages over TCP, and an HTTP gateway that asks it. Start the service with createMicroservice, answer patterns with @MessagePattern, register a client with ClientsModule and send it messages.

What you will learn

Read the theory for Your first microservice

All Microservices lessons

All NestJS courses

loading types…

What you'll learn

  • Explain what a microservice is in Nest: an application whose transport is not HTTP, answering messages matched by pattern
  • Start a TCP microservice with NestFactory.createMicroservice and a port, and know why it must listen before anything calls it
  • Answer request-response messages with @MessagePattern in a controller, with object or string patterns
  • Register a ClientProxy with ClientsModule.register, inject it by name, and send() messages: a cold Observable, returned from a route or awaited with firstValueFrom