How to use the @nestjs/microservices.Transport.REDIS 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 new-eden-social / new-eden-social / src / services / notification / server.ts View on Github external
const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(NotificationModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'notification',
      protoPath: join(__dirname, 'src/grpc/notification.proto'),
    },
  });

  app.connectMicroservice({
    transport: Transport.REDIS,
    options: {
      url: process.env.REDIS_HOST,
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github nestjs / nest / integration / microservices / e2e / sum-redis.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [RedisController],
    }).compile();

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

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

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

    app.connectMicroservice({
      transport: Transport.REDIS,
      options: {
        url: 'redis://0.0.0.0:6379',
      },
    });
    app.connectMicroservice({
      transport: Transport.REDIS,
      options: {
        url: 'redis://0.0.0.0:6379',
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github WonderPanda / nestjs-microservice-architecture / services / graphqlapi / src / catalog / catalog-item / catalog-item-client.service.ts View on Github external
import { Injectable } from '@nestjs/common';
import { Client, ClientProxy, Transport } from '@nestjs/microservices';
import { CatalogItem } from 'schemas/graphql';

const REDIS_HOST = process.env.REDIS_HOST || 'localhost';
const REDIS_PORT = process.env.REDIS_PORT || 6379;

@Injectable()
export class CatalogItemService {
  @Client({
    transport: Transport.REDIS,
    options: { url: `redis://${REDIS_HOST}:${REDIS_PORT}` }
  })
  client: ClientProxy;

  public async getCatalogItems(): Promise {
    const response = await this.client.send(
      { type: 'get-catalog-items' },
      { someImaginaryParams: 42 }
    );
    return response.toPromise();
  }
}
github nestjs / terminus / sample / 002-microservice-app / src / health.module.ts View on Github external
async () =>
          microservice.pingCheck('redis', {
            transport: Transport.REDIS,
            options: {
              url: 'redis://localhost:6379',
            },
          }),
      ],
github nestjs / nest / integration / microservices / src / redis / redis.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 RedisController {
  static IS_NOTIFIED = false;

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

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

  @Post('stream')
  @HttpCode(200)
  stream(@Body() data: number[]): Observable {
    return this.client
      .send({ cmd: 'streaming' }, data)
      .pipe(scan((a, b) => a + b));
  }
github nestjs / nest / integration / microservices / src / redis / redis-broadcast.controller.ts View on Github external
import { Controller, Get } from '@nestjs/common';
import {
  Client,
  MessagePattern,
  ClientProxy,
  Transport,
} from '@nestjs/microservices';
import { Observable } from 'rxjs';
import { scan, take } from 'rxjs/operators';

@Controller()
export class RedisBroadcastController {
  @Client({ transport: Transport.REDIS })
  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));
  }
}