How to use the @nestjs/microservices.Transport.TCP 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 m24927605 / Nestjs30Days / day14 / Day14_MicroServices / project / src / server.ts View on Github external
async function bootstrap() {
	const app = await NestFactory.create(ApplicationModule);
	app.connectMicroservice({
	  transport: Transport.TCP,
	});
  
	await app.startAllMicroservicesAsync();
	await app
	.listen(3001).then(()=>{
		console.log('MicroService is starting.');
	})
	.catch((error)=>{
		console.error('Something wrong happened,',error);
	})
  }
  bootstrap();
github NarHakobyan / awesome-nest-boilerplate / src / main.hmr.ts View on Github external
app.useGlobalPipes(
        new ValidationPipe({
            whitelist: true,
            transform: true,
            dismissDefaultMessages: true,
            validationError: {
                target: false,
            },
        }),
    );

    const configService = app.select(SharedModule).get(ConfigService);

    app.connectMicroservice({
        transport: Transport.TCP,
        options: {
            port: configService.getNumber('TRANSPORT_PORT'),
            retryAttempts: 5,
            retryDelay: 3000,
        },
    });

    await app.startAllMicroservicesAsync();

    if (['development', 'staging'].includes(configService.nodeEnv)) {
        setupSwagger(app);
    }

    const port = configService.getNumber('PORT');
    await app.listen(port);
github nestjs / terminus / e2e / health-checks / microservice.health.e2e-spec.ts View on Github external
async () =>
                  microservice.pingCheck('tcp', {
                    timeout: 1,
                    transport: Transport.TCP,
                    options: {
                      host: '0.0.0.0',
                      port: 8889,
                    },
                  }),
              ],
github NarHakobyan / awesome-nest-boilerplate / src / main.ts View on Github external
app.useGlobalPipes(
        new ValidationPipe({
            whitelist: true,
            transform: true,
            dismissDefaultMessages: true,
            validationError: {
                target: false,
            },
        }),
    );

    const configService = app.select(SharedModule).get(ConfigService);

    app.connectMicroservice({
        transport: Transport.TCP,
        options: {
            port: configService.getNumber('TRANSPORT_PORT'),
            retryAttempts: 5,
            retryDelay: 3000,
        },
    });

    await app.startAllMicroservicesAsync();

    if (['development', 'staging'].includes(configService.nodeEnv)) {
        setupSwagger(app);
    }

    const port = configService.getNumber('PORT');
    await app.listen(port);
github neoteric-eu / nestjs-auth / src / app / home / home.controller.ts View on Github external
import crypto from 'crypto';
import {AppLogger} from '../app.logger';
import {HomeService} from './home.service';
import {HomePipe} from './pipe/home.pipe';
import {HomeEntity} from './entity';
import {ConvertTemplateDto} from './dto/convert-template.dto';
import {HomePdfService} from './home-pdf.service';
import {AuthGuard} from '@nestjs/passport';

@ApiUseTags('home')
@Controller('home')
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
export class HomeController {

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

	private logger = new AppLogger(HomeController.name);

	constructor(
		private readonly homeService: HomeService,
		private readonly homePdfService: HomePdfService
	) {

	}

	@Post('import/addresses')
	@HttpCode(200)
	@ApiResponse({status: 204, description: 'NO CONTENT'})
	public async importAddresses(): Promise {
		this.logger.silly(`[importAddresses] execute `);
github neoteric-eu / nestjs-auth / src / app / home-media / home-media.resolver.ts View on Github external
import {MEDIA_CMD_DELETE} from '../media/media.constants';
import {HomeMediaService} from './home-media.service';
import {CreateHomeMediaInput, UpdateHomeMediaInput, DeleteHomeMediaInput, HomeMedia} from '../graphql.schema';
import {GraphqlGuard} from '../_helpers';
import {User as CurrentUser} from '../_helpers/graphql/user.decorator';
import {UserEntity as User} from '../user/entity';
import {AppLogger} from '../app.logger';

@Resolver('HomeMedia')
@UseGuards(GraphqlGuard)
export class HomeMediaResolver {

	private pubSub = new PubSub();
	private logger = new AppLogger(HomeMediaResolver.name);

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


	constructor(private readonly homeMediaService: HomeMediaService) {
	}

	@Query('getHomeMedia')
	async findAll(@Args('homeId') homeId: string): Promise {
		return this.homeMediaService.findAll({where: {homeId: {eq: homeId}}});
	}

	@Mutation('createHomeMedia')
	async create(@CurrentUser() user: User, @Args('createHomeMediaInput') args: CreateHomeMediaInput): Promise {
		const createdHomeMedia = await this.homeMediaService.create(args);
		await this.pubSub.publish('homeMediaCreated', {homeMediaCreated: createdHomeMedia});
		return createdHomeMedia;
github vendure-ecommerce / vendure / packages / core / src / bootstrap.ts View on Github external
function workerWelcomeMessage(config: VendureConfig) {
    let transportString = '';
    let connectionString = '';
    const transport = (config.workerOptions && config.workerOptions.transport) || Transport.TCP;
    transportString = ` with ${Transport[transport]} transport`;
    const options = (config.workerOptions as TcpClientOptions).options;
    if (options) {
        const { host, port } = options;
        connectionString = ` at ${host || 'localhost'}:${port}`;
    }
    Logger.info(`Vendure Worker started${transportString}${connectionString}`);
}
github nestjs / terminus / e2e / helper / bootstrap-module.ts View on Github external
async function bootstrapMicroservice(tcpPort: number) {
  const tcpApp = await NestFactory.createMicroservice(ApplicationModule, {
    transport: Transport.TCP,
    options: {
      host: '0.0.0.0',
      port: tcpPort,
    },
  });

  await tcpApp.listenAsync();
}
github nestjs / nest / integration / microservices / src / app.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 AppController {
  static IS_NOTIFIED = false;

  @Client({ transport: Transport.TCP })
  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 neoteric-eu / nestjs-auth / src / app / home / home.resolver.ts View on Github external
import {HomeFavoriteService} from '../home-favorite/home-favorite.service';
import {HomeMediaEntity} from '../home-media/entity';
import {HomeMediaService} from '../home-media/home-media.service';
import {UserEntity as User} from '../user/entity/user.entity';
import {UserService} from '../user/user.service';
import {AttomDataApiService} from './attom-data-api.service';
import {CreateHomeDto, DeleteHomeDto, UpdateHomeDto} from './dto';
import {HomeEntity} from './entity';
import {FoxyaiService} from './foxyai.service';
import {HOME_CMD_DELETE} from './home.constants';
import {HomeService} from './home.service';

@Resolver('Home')
export class HomeResolver {

	@Client({ transport: Transport.TCP })
	private client: ClientProxy;
	private pubSub = new PubSub();
	private logger = new AppLogger(HomeResolver.name);

	constructor(private readonly homeService: HomeService,
							private readonly attomDataService: AttomDataApiService,
							private readonly userService: UserService,
							private readonly homeMediaService: HomeMediaService,
							private readonly homeFavoriteService: HomeFavoriteService,
							private readonly contractService: ContractService,
							private readonly foxyaiService: FoxyaiService
	) {
	}

	@Query('getAVMDetail')
	async getDetail(@Args('getAVMDetailInput') args: GetAVMDetailInput) {