How to use the @nestjs/microservices.Transport.MQTT 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 / sum-mqtt.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [MqttController],
    }).compile();

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

    app.connectMicroservice({
      transport: Transport.MQTT,
      options: {
        url: 'mqtt://0.0.0.0:1883',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github nestjs / nest / integration / microservices / e2e / disconnected-client.spec.ts View on Github external
it(`MQTT`, () => {
    return request(server)
      .post('/')
      .send({
        transport: Transport.MQTT,
        options: {
          host: 'mqtt://broker.hivemq.com',
          port: 183,
        },
      })
      .expect(408);
  });
github nestjs / nest / integration / microservices / e2e / broadcast-mqtt.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [MqttBroadcastController],
    }).compile();

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

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

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

    app.connectMicroservice({
      transport: Transport.MQTT,
      options: {
        host: '0.0.0.0',
      },
    });
    app.connectMicroservice({
      transport: Transport.MQTT,
      options: {
        host: '0.0.0.0',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github nestjs / nest / integration / microservices / src / mqtt / mqtt-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 MqttBroadcastController {
  @Client({ transport: Transport.MQTT })
  client: ClientProxy;

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

  @MessagePattern({ cmd: 'broadcast' })
  replyBroadcast(): Observable {
    return new Observable(observer => observer.next(1));
  }
}
github nestjs / nest / integration / microservices / src / mqtt / mqtt.controller.ts View on Github external
import { Body, Controller, HttpCode, Post, Query } from '@nestjs/common';
import {
  Client,
  ClientProxy,
  EventPattern,
  MessagePattern,
  Transport,
} from '@nestjs/microservices';
import { from, Observable, of } from 'rxjs';
import { scan } from 'rxjs/operators';

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

  @Client({ transport: Transport.MQTT })
  client: ClientProxy;

  @Post()
  @HttpCode(200)
  async call(
    @Query('command') cmd,
    @Body() data: number[],
  ): Promise> {
    await this.client.connect();
    return this.client.send({ cmd }, data);
  }

  @Post('stream')
  @HttpCode(200)
  stream(@Body() data: number[]): Observable {
    return this.client