Server bootstrap
To get started, make sure @nestjs/microservices
is installed within your project. This module provides the client, server, and accompanying utilities needed to convert a Nest.js API application into a microservices application. Finally, we will modify our blog application’s bootstrap to enable microservices.
async
function
bootstrap() {
const
app
=
await
NestFactory
.
create
(
AppModule
);
app
.
connectMicroservice
({
transport
:Transport.TCP
,
options
:
{
port
:5667
}
});
await
app
.
startAllMicroservicesAsync
();
await
app
.
listen
(
3001
);
}
The connectMicroservice
method instructs the NestApplication to setup a new NestMicroservice context. The object provides the options for setting up the NestMicroservice context. Here, we are keeping things simple and using the standard TCP transport provided with Nest.js. A call to startAllMicroservicesAsync
starts up the NestMicroservice context. Be sure to do this before calling...