File tree Expand file tree Collapse file tree
sample/03-microservices/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 WebSocketAdapter ,
1010} from '@nestjs/common' ;
1111import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface' ;
12- import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface' ;
1312import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface' ;
1413import { Logger } from '@nestjs/common/services/logger.service' ;
1514import { loadPackage } from '@nestjs/common/utils/load-package.util' ;
@@ -171,7 +170,7 @@ export class NestApplication extends NestApplicationContext
171170 this . routesResolver . registerExceptionHandler ( ) ;
172171 }
173172
174- public connectMicroservice ( options : MicroserviceOptions ) : INestMicroservice {
173+ public connectMicroservice < T extends object > ( options : T ) : INestMicroservice {
175174 const { NestMicroservice } = loadPackage (
176175 '@nestjs/microservices' ,
177176 'NestFactory' ,
Original file line number Diff line number Diff line change 44 INestApplicationContext ,
55 INestMicroservice ,
66} from '@nestjs/common' ;
7- import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface' ;
87import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface' ;
98import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface' ;
109import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface' ;
@@ -91,9 +90,9 @@ export class NestFactoryStatic {
9190 * @returns A promise that, when resolved,
9291 * contains a reference to the NestMicroservice instance.
9392 */
94- public async createMicroservice (
93+ public async createMicroservice < T extends object > (
9594 module : any ,
96- options ?: NestMicroserviceOptions & MicroserviceOptions ,
95+ options ?: NestMicroserviceOptions & T ,
9796 ) : Promise < INestMicroservice > {
9897 const { NestMicroservice } = loadPackage (
9998 '@nestjs/microservices' ,
Original file line number Diff line number Diff line change 1- import { MqttClientOptions } from '@nestjs/common/interfaces/external/mqtt-options.interface ' ;
1+ import { Transport } from '../enums/transport.enum ' ;
22import {
3- KafkaConfig ,
3+ CompressionTypes ,
44 ConsumerConfig ,
5+ KafkaConfig ,
56 ProducerConfig ,
6- CompressionTypes ,
7- } from '@nestjs/common/interfaces/external/kafka-options.interface' ;
8- import { Transport } from '../enums/transport.enum' ;
7+ } from '../external/kafka-options.interface' ;
8+ import { MqttClientOptions } from '../external/mqtt-options.interface' ;
99import { Server } from '../server/server' ;
1010import { CustomTransportStrategy } from './custom-transport-strategy.interface' ;
1111import { Deserializer } from './deserializer.interface' ;
Original file line number Diff line number Diff line change 44 INestMicroservice ,
55 Logger ,
66} from '@nestjs/common' ;
7- import { MicroserviceOptions } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface' ;
87import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface' ;
98import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface' ;
109import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface' ;
@@ -43,8 +42,8 @@ export class TestingModule extends NestApplicationContext {
4342 return this . createAdapterProxy < T > ( instance , httpAdapter ) ;
4443 }
4544
46- public createNestMicroservice (
47- options : NestMicroserviceOptions & MicroserviceOptions ,
45+ public createNestMicroservice < T extends object > (
46+ options : NestMicroserviceOptions & T ,
4847 ) : INestMicroservice {
4948 const { NestMicroservice } = loadPackage (
5049 '@nestjs/microservices' ,
Original file line number Diff line number Diff line change 11import { NestFactory } from '@nestjs/core' ;
2- import { Transport } from '@nestjs/microservices' ;
2+ import { TcpOptions , Transport } from '@nestjs/microservices' ;
33import { AppModule } from './app.module' ;
44
55async function bootstrap ( ) {
66 /**
77 * This example contains a hybrid application (HTTP + TCP)
88 * You can switch to a microservice with NestFactory.createMicroservice() as follows:
99 *
10- * const app = await NestFactory.createMicroservice(AppModule, {
10+ * const app = await NestFactory.createMicroservice<TcpOptions> (AppModule, {
1111 * transport: Transport.TCP,
1212 * options: { retryAttempts: 5, retryDelay: 3000 },
1313 * });
1414 * await app.listenAsync();
1515 *
1616 */
1717 const app = await NestFactory . create ( AppModule ) ;
18- app . connectMicroservice ( {
18+ app . connectMicroservice < TcpOptions > ( {
1919 transport : Transport . TCP ,
2020 options : { retryAttempts : 5 , retryDelay : 3000 } ,
2121 } ) ;
You can’t perform that action at this time.
0 commit comments