Hi, I am new to NestJS but I think that this question can help others.
I followed this video: https://www.youtube.com/watch?v=C250DCwS81Q
I created a api-gateway project with that main.ts:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
and app.service.ts:
@Injectable()
export class AppService {
private readonly users = [];
constructor(
@Inject('WALLET_FACTORY') private readonly walletFactory: ClientProxy,
) {}
getHello(): string {
return 'Hello World!';
}
createWallet(createWalletRequest: CreateWalletRequest) {
this.users.push(createWalletRequest);
this.walletFactory.emit(
'create_wallet_request',
new CreateWalletRequestEvent(createWalletRequest.eoaAddress),
);
}
}
My other project ( a micro service ) is called wallet-factory, where main.ts:
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.TCP,
},
);
await app.listen();
}
bootstrap();
app.controller.ts:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
@EventPattern('create_wallet_request', Transport.TCP)
handleCreateWalletRequest(data: CreateWalletRequestEvent) {
this.appService.handleCreateWalletRequest(data);
}
}
When I try to test the createWallet API with postman the connection is stuck in state "Sending Request".
I run both project in my localhost (Windows 11), I would also like to containerize both.
Can anyone help me? The problem may be silly but I don't see it 😩
Thank you!!
In this short tutorial, I show you how to create a Nest.js project with Microservices along with an API Gateway.
Github Repo: https://github.com/mguay22/nestjs-microservices
Nest.js Documentation: https://docs.nestjs.com/microservices/basics
Get my highly rated NestJS Microservices Course at a discount: https://michaelguay.dev/