NATS

The NATS is a simple, high performance open source messaging system.

Installation

Before we start, we have to install required package:

  1. $ npm i --save nats

Overview

In order to switch to NATS transporter, we need to modify an options object passed to the createMicroservice() method.

  1. @@filename(main)
  2. const app = await NestFactory.createMicroservice(ApplicationModule, {
  3. transport: Transport.NATS,
  4. options: {
  5. url: 'nats://localhost:4222',
  6. },
  7. });

info Hint Transport enumerator is imported from the @nestjs/microservices package.

Options

There are a bunch of available options that determine a transporter behavior. They are well-described here. Also, there is an additional queue property which allows you specifying a name of the queue that your server should subscribe to (leave undefined if you don’t want use any particular queue)