How to use the @nestjs/core.NestFactory.createMicroservice function in @nestjs/core

To help you get started, weโ€™ve selected a few @nestjs/core 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 vendure-ecommerce / vendure / packages / core / src / bootstrap.ts View on Github external
async function bootstrapWorkerInternal(userConfig: Partial): Promise {
    const config = disableSynchronize(await preBootstrapConfig(userConfig));
    if (!config.workerOptions.runInMainProcess && (config.logger as any).setDefaultContext) {
        (config.logger as any).setDefaultContext('Vendure Worker');
    }
    Logger.useLogger(config.logger);
    Logger.info(`Bootstrapping Vendure Worker (pid: ${process.pid})...`);

    const workerModule = await import('./worker/worker.module');
    DefaultLogger.hideNestBoostrapLogs();
    const workerApp = await NestFactory.createMicroservice(workerModule.WorkerModule, {
        transport: config.workerOptions.transport,
        logger: new Logger(),
        options: config.workerOptions.options,
    });
    DefaultLogger.restoreOriginalLogLevel();
    workerApp.useLogger(new Logger());
    workerApp.enableShutdownHooks();

    // A work-around to correctly handle errors when attempting to start the
    // microservice server listening.
    // See https://github.com/nestjs/nest/issues/2777
    // TODO: Remove if & when the above issue is resolved.
    await new Promise((resolve, reject) => {
        (workerApp as any).server.server.on('error', (e: any) => {
            reject(e);
        });
github vendure-ecommerce / vendure / packages / testing / src / test-server.ts View on Github external
private async bootstrapForTesting(
        userConfig: Partial,
    ): Promise<[INestApplication, INestMicroservice | undefined]> {
        const config = await preBootstrapConfig(userConfig);
        Logger.useLogger(config.logger);
        const appModule = await import('@vendure/core/dist/app.module');
        try {
            DefaultLogger.hideNestBoostrapLogs();
            const app = await NestFactory.create(appModule.AppModule, { cors: config.cors, logger: false });
            let worker: INestMicroservice | undefined;
            await app.listen(config.port);
            if (config.workerOptions.runInMainProcess) {
                const workerModule = await import('@vendure/core/dist/worker/worker.module');
                worker = await NestFactory.createMicroservice(workerModule.WorkerModule, {
                    transport: config.workerOptions.transport,
                    logger: new Logger(),
                    options: config.workerOptions.options,
                });
                await worker.listenAsync();
            }
            DefaultLogger.restoreOriginalLogLevel();
            return [app, worker];
        } catch (e) {
            console.log(e);
            throw e;
        }
    }
}
github TheAifam5 / nestjs-docker-microservices / microservices / database / src / main.hmr.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, OPTIONS);
  app.listen(() => console.log('Database Microservice is listening with HMR enabled'));

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}
bootstrap();
github TheAifam5 / nestjs-docker-microservices / microservices / users / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.createMicroservice(ApplicationModule, OPTIONS);
  app.listen(() => console.log('Users Microservice is listening'));
}
bootstrap();
github TheAifam5 / nestjs-docker-microservices / microservices / database / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, OPTIONS);
  app.listen(() => console.log('Database Microservice is listening'));
}
bootstrap();
github backstopmedia / nest-book-example / src / main.cluster.ts View on Github external
async function bootstrapRpc() {
    const rpcApp = await NestFactory.createMicroservice(
        AppModule,
        microserviceServerConfig('nestjs_book')
    );
    rpcApp.useGlobalFilters(new RpcValidationFilter());

    await rpcApp.listenAsync();
}
github WonderPanda / nestjs-microservice-architecture / services / catalog / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.REDIS,
    options: {
      retryAttempts: 5,
      retryDelay: 1000,
      url: `redis://${REDIS_HOST}:${REDIS_PORT}`
    }
  });

  await app.listenAsync();
}
bootstrap();
github notadd / nt-module-cms / src / main.ts View on Github external
async function bootstrap() {
    const app = await NestFactory.createMicroservice(CmsModule, {
        transport: Transport.GRPC,
        options: {
            url: 'localhost:50052',
            package: 'nt_module_cms',
            protoPath: join(__dirname, 'nt_module_cms.proto'),
            loader: {
                arrays: true
            }
        }
    });
    await app.listenAsync();
}
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();
}