Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Distribuidos-Org/ms-alumnos/llms.txt
Use this file to discover all available pages before exploring further.
ms-alumnos uses NATS as its exclusive transport layer via @nestjs/microservices with Transport.NATS. There are no HTTP endpoints, no REST controllers, and no TCP listeners — every operation is invoked by sending a NATS message to the appropriate subject and waiting for the reply. This design makes the service fully decoupled from any particular HTTP gateway and easy to scale horizontally behind a NATS cluster.
Message patterns
Every student operation is exposed via the@MessagePattern decorator with a cmd discriminator. When a NATS message arrives whose subject matches a registered pattern, NestJS dispatches it to the corresponding handler in AlumnosController.
The following five commands are available:
cmd value | Handler | Description |
|---|---|---|
create_alumno | AlumnosController.create | Creates a new student record from a CreateAlumnoDto payload. |
find_all_alumnos | AlumnosController.findAll | Returns a paginated list of students. Accepts { page, limit } via PaginationDto. |
find_one_alumno | AlumnosController.findOne | Fetches a single student by numeric id. |
update_alumno | AlumnosController.update | Updates an existing student. Payload must include id plus any fields to change (UpdateAlumnoDto). |
remove_alumno | AlumnosController.remove | Deletes a student by numeric id. Returns a confirmation message on success. |
Request-reply semantics
NATS supports two messaging models: publish-subscribe (fire-and-forget) and request-reply (synchronous RPC).ms-alumnos uses request-reply for all operations.
In request-reply mode:
- The caller publishes a message to a subject (e.g.
{ cmd: 'find_one_alumno' }) and includes a private reply subject in the message envelope. ms-alumnosprocesses the message, then publishes its response to that reply subject.- The caller receives the response on the reply subject, completing the round-trip.
ClientProxy.send() does in NestJS — it transparently manages the reply subject and returns an Observable that resolves when the reply arrives. It is fundamentally different from ClientProxy.emit(), which publishes with no reply subject (fire-and-forget) and cannot be used to retrieve data.
Multi-server configuration
ms-alumnos supports connecting to multiple NATS servers for redundancy and load distribution. The NATS_SERVERS environment variable is a comma-separated list of server URLs. src/config/envs.ts splits this string into an array and validates it with Joi before the application starts:
envs.natsServers array is passed directly to the transport options in main.ts:
.env entry for multiple servers looks like:
Connecting from another service
Any service that needs to communicate withms-alumnos can use the nats npm package directly for a lightweight, low-dependency connection. The example below demonstrates a full request-reply round-trip for find_one_alumno:
ClientProxy via @nestjs/microservices, which provides the same request-reply behaviour with full TypeScript integration and Observable-based error handling.
Error propagation
When a handler throws — whether from a failed database lookup, a DTO validation failure, or any other condition — theMicroserviceExceptionFilter intercepts the exception and wraps it as an RpcException with a structured { status, message } payload. This error object travels back to the caller over the NATS reply subject, exactly as a successful response would.
The caller receives a rejected Observable (or a thrown error if using await). The client-gateway is responsible for mapping the status field back to an HTTP status code before responding to the original HTTP client.
For the full exception-handling flow, see Error Handling.