graph LR
NestMicroservice["NestMicroservice"]
ServerFactory["ServerFactory"]
ClientProxyFactory["ClientProxyFactory"]
Server["Server"]
ClientProxy["ClientProxy"]
MicroservicesModule["MicroservicesModule"]
ListenersController["ListenersController"]
RpcContextCreator["RpcContextCreator"]
NestMicroservice -- "uses" --> ServerFactory
NestMicroservice -- "leverages" --> MicroservicesModule
ServerFactory -- "creates" --> Server
ClientProxyFactory -- "creates" --> ClientProxy
MicroservicesModule -- "calls" --> ClientProxyFactory
MicroservicesModule -- "interacts with" --> ListenersController
Server -- "routes messages to" --> ListenersController
ListenersController -- "uses" --> RpcContextCreator
The NestJS Microservices subsystem provides a robust framework for building distributed applications. At its core, the NestMicroservice acts as the application's entry point, orchestrating the setup and lifecycle of microservices. It relies on ServerFactory to provision protocol-specific Server instances for handling incoming requests and ClientProxyFactory to create ClientProxy instances for outgoing communication. The MicroservicesModule seamlessly integrates these capabilities into the NestJS module system, managing the registration of message handlers and client proxies. The ListenersController plays a crucial role in discovering and routing incoming messages to the correct handlers, while the RpcContextCreator ensures that these handlers execute within a properly configured RPC context, applying necessary pipes, guards, and interceptors. This modular design promotes clear separation of concerns and extensibility for various transport protocols.
Acts as the primary application bootstrap and orchestrator for microservice applications. It manages the lifecycle of the microservice, from creation and listening for incoming messages to graceful shutdown.
Related Classes/Methods:
A factory component responsible for creating concrete server instances based on the specified transport protocol (e.g., TCP, Redis, NATS, Kafka, MQTT, gRPC). It abstracts the complexity of instantiating different server types.
Related Classes/Methods:
A factory component responsible for creating concrete client proxy instances for various transport protocols. These client proxies are used by other parts of the application to send messages and emit events to microservice servers.
Related Classes/Methods:
Defines the common interface and abstract logic for all microservice servers. Concrete implementations (e.g., TcpServer, RedisServer) extend this class to handle protocol-specific server logic, including listening for messages, adding message handlers, and dispatching them. It also manages the serialization and deserialization of messages.
Related Classes/Methods:
Provides the abstract interface for sending messages (send) and emitting events (emit) to microservice servers. Concrete implementations handle the specifics of communication over different transport protocols, abstracting the underlying network details. It also handles serialization and deserialization of outgoing and incoming data.
Related Classes/Methods:
Integrates microservice capabilities into the Nest application's module system. It registers client proxies and message pattern handlers, making microservice features available within the application context. It uses ListenersController to bind listeners and clients.
Related Classes/Methods:
Manages the discovery and registration of message pattern handlers (methods decorated with @MessagePattern()) and assigns client proxies to properties. It acts as a dispatcher or router for incoming microservice messages, directing them to the correct handler and creating request-scoped handlers.
Related Classes/Methods:
Creates the execution context for RPC (Remote Procedure Call) handlers. This involves applying pipes, guards, and resolving parameters, ensuring that the handler executes within the correct environment. It uses PipesContextCreator, GuardsContextCreator, and InterceptorsContextCreator.
Related Classes/Methods: