Built-in transports
The TCP transport is only one of several transports Nest.js has built-in. Using the TCP transport, we had to bind our NestMicroservice context to an additional port, taking up yet another port on the server, and ensuring our NestMicroservice context was running before starting the NestApplication context. Other built-in transports can overcome these limitations and add additional benefits.
Redis
Redis is a simple in-memory data store that can be used as a pub-sub message broker. The Redis transport makes use of the redis NPM package and a Redis server to pass messages between the NestApplication and NestMicroservice contexts. To use the Redis transport, we need to update our bootstrap
method to use the correct NestMicroservice configuration.
async
function
bootstrap() {
const
app
=
await
NestFactory
.
create
(
AppModule
);
app
.
connectMicroservice
({
transport
:Transport.REDIS
,
options
:
{
url
:process.env.REDIS_URL
}
});
...