Streams and timeouts — Microservices · NestJS

Replies that arrive over time and replies that never arrive: the cats service streams search results one cat at a time, the gateway collects them, and a census that takes too long is cut off with a timeout and answered 504.

What you will learn

Read the theory for Streams and timeouts

All Microservices lessons

All NestJS courses

loading types…

What you'll learn

  • Return an Observable from a message handler to send several replies, and know that each one crosses the wire as it is emitted
  • Read parts of a payload with @Payload('key') and the transport's context with @Ctx(), and know which arguments an undecorated handler receives
  • Collect a stream on the client with toArray() and lastValueFrom(), and know why firstValueFrom() and returning the Observable from a route both answer with a single value
  • Bound a call with the timeout() operator and turn its TimeoutError into a 504 at the gateway