Custom transport
A custom transport allows you to define a new microservice client and server for communicating between the NestApplication and NestMicroservice contexts. You may want to create a custom transport strategy for a number of reasons: you or your company already have a message broker service that is does not have a built-in Nest.js transport, or you need to customize how one of the built-in transports works. For the purpose of our example, we will work through implementing a new RabbitMQ transport.
export
class
RabbitMQTransportServer
extends
Server
implements
CustomTransportStrategy
{
private
server
:amqp.Connection
=
null
;
private
channel
:amqp.Channel
=
null
;
constructor
(
private
readonly
url
:string
,
private
readonly
queue
:string
)
{
super
();
}
}
Nest.js requires all custom transports to implement the CustomTransportStrategy
interface. This forces us to define our own listen
and close
methods. In our example, we connect to...