How to use the @nestjs/microservices.Transport.NATS function in @nestjs/microservices

To help you get started, weโ€™ve selected a few @nestjs/microservices examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nestjs / nest / integration / microservices / e2e / disconnected-client.spec.ts View on Github external
it(`NATS`, () => {
    return request(server)
      .post('/')
      .send({
        transport: Transport.NATS,
        options: {
          url: 'nats://localhost:4224',
        },
      })
      .expect(408);
  });
github nestjs / nest / integration / microservices / e2e / broadcast-nats.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [NatsBroadcastController],
    }).compile();

    app = module.createNestApplication();
    server = app.getHttpAdapter().getInstance();

    app.connectMicroservice({
      transport: Transport.NATS,
      options: {
        url: 'nats://0.0.0.0:4222',
      },
    });
    app.connectMicroservice({
      transport: Transport.NATS,
      options: {
        url: 'nats://0.0.0.0:4222',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github nestjs / nest / integration / microservices / e2e / sum-nats.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [NatsController],
    }).compile();

    app = module.createNestApplication();
    server = app.getHttpAdapter().getInstance();

    app.connectMicroservice({
      transport: Transport.NATS,
      options: {
        url: 'nats://0.0.0.0:4222',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github nestjs / nest / integration / microservices / e2e / broadcast-nats.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [NatsBroadcastController],
    }).compile();

    app = module.createNestApplication();
    server = app.getHttpAdapter().getInstance();

    app.connectMicroservice({
      transport: Transport.NATS,
      options: {
        url: 'nats://0.0.0.0:4222',
      },
    });
    app.connectMicroservice({
      transport: Transport.NATS,
      options: {
        url: 'nats://0.0.0.0:4222',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github nestjs / nest / integration / microservices / src / nats / nats.controller.ts View on Github external
EventPattern,
  MessagePattern,
  NatsContext,
  Payload,
  RpcException,
  Transport,
} from '@nestjs/microservices';
import { from, Observable, of, throwError } from 'rxjs';
import { catchError, scan } from 'rxjs/operators';

@Controller()
export class NatsController {
  static IS_NOTIFIED = false;

  @Client({
    transport: Transport.NATS,
    options: {
      url: 'nats://localhost:4222',
    },
  })
  client: ClientProxy;

  @Post()
  @HttpCode(200)
  async call(
    @Query('command') cmd,
    @Body() data: number[],
  ): Promise> {
    await this.client.connect();
    return this.client.send(cmd, data);
  }
github ConnextProject / indra / modules / node / src / main.ts View on Github external
async function bootstrap(): Promise {
  const app = await NestFactory.create(AppModule);
  const config = app.get(ConfigService);
  const messagingUrl = config.getMessagingConfig().messagingUrl;
  app.connectMicroservice({
    options: {
      servers: typeof messagingUrl === "string" ? [messagingUrl] : messagingUrl,
    },
    transport: Transport.NATS,
  });
  await app.startAllMicroservicesAsync();
  await app.listen(config.getPort());
}
bootstrap();
github nestjs / nest / integration / microservices / src / nats / nats-broadcast.controller.ts View on Github external
import { Controller, Get } from '@nestjs/common';
import {
  Client,
  ClientProxy,
  MessagePattern,
  Transport,
} from '@nestjs/microservices';
import { Observable } from 'rxjs';
import { scan, take } from 'rxjs/operators';

@Controller()
export class NatsBroadcastController {
  @Client({ transport: Transport.NATS })
  client: ClientProxy;

  @Get('broadcast')
  multicats() {
    return this.client.send('broadcast.test', {}).pipe(
      scan((a, b) => a + b),
      take(2),
    );
  }

  @MessagePattern('broadcast.*')
  replyBroadcast(): Observable {
    return new Observable(observer => observer.next(1));
  }
}
github ConnextProject / indra / modules / node / src / messaging / messaging.provider.ts View on Github external
useFactory: (config: ConfigService): ClientProxy => {
    const messagingUrl = config.getMessagingConfig().messagingUrl;
    return ClientProxyFactory.create({
      options: {
        servers: typeof messagingUrl === "string" ? [messagingUrl] : messagingUrl,
      },
      transport: Transport.NATS,
    });
  },
};