Files
main.tsmain
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
Press Run tests to start the app. Its log appears here.Graded endpoints
The gateway sends { cmd: 'find-all' } over TCP and answers with the service's reply: the gateway has no cats of its own
{ cmd: 'find-one' } carries the id as its payload, a number (ParseIntPipe), which the service's handler receives as its argument
The reply follows the payload, so the handler really reads the id it was sent
The service replies null; the gateway waits for the reply with firstValueFrom and turns null into a 404