Consider a NestJS hybrid application that starts both an HTTP server and a microservice listener. What will happen when you send an HTTP request to the app's endpoint?
import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { Transport } from '@nestjs/microservices'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.connectMicroservice({ transport: Transport.TCP }); await app.startAllMicroservices(); await app.listen(3000); } bootstrap();
Think about how NestJS handles multiple listeners in a hybrid app.
In a NestJS hybrid app, you can start both HTTP and microservice listeners. The HTTP server listens on the specified port, and the microservice listens on its transport layer (TCP here). Both run simultaneously.
In a NestJS hybrid app, you have two ways to start servers: app.listen() for HTTP and app.startAllMicroservices() for microservices. What is the effect of calling app.listen() before app.startAllMicroservices()?
async function bootstrap() { const app = await NestFactory.create(AppModule); app.connectMicroservice({ transport: Transport.REDIS }); await app.listen(3000); await app.startAllMicroservices(); } bootstrap();
Consider how async/await works and how NestJS manages multiple listeners.
Calling app.listen() starts the HTTP server and returns a promise that resolves when the server is ready. Then app.startAllMicroservices() starts the microservice listeners. Both run correctly regardless of order.
Choose the code snippet that correctly sets up a NestJS hybrid application with an HTTP server and a RabbitMQ microservice listener.
Check the property name for RabbitMQ connection URLs in NestJS microservice options.
The correct property for RabbitMQ connection URLs is urls as an array of strings. Option B uses this correctly. Other options use incorrect property names or types.
Given the following code, why does the microservice listener not receive any messages?
async function bootstrap() { const app = await NestFactory.create(AppModule); app.connectMicroservice({ transport: Transport.TCP }); await app.listen(3000); // Missing await app.startAllMicroservices(); } bootstrap();
Check if the microservice listener is actually started.
Calling app.connectMicroservice() only configures the microservice. You must call app.startAllMicroservices() to start listening. Without it, microservice messages are not received.
Why would a developer choose to build a NestJS hybrid application instead of separate HTTP and microservice apps?
Think about code reuse and architecture benefits.
A NestJS hybrid app runs both HTTP and microservice servers in the same process and shares the same dependency injection container. This reduces code duplication and makes maintenance easier.