This app responds to HTTP GET requests with a greeting. It also listens as a TCP microservice for messages with command 'sum' and returns the sum of numbers.
B. connectMicroservice() does not accept transport option
C. startAllMicroservices() must be called before app.listen()
D. Missing await before connectMicroservice()
Solution
Step 1: Check method call order
In NestJS, microservices must be started before the HTTP server listens, so startAllMicroservices() should be before app.listen().
Step 2: Validate other options
connectMicroservice() accepts transport option; AppModule supports microservices; connectMicroservice() is synchronous, no await needed.
Final Answer:
startAllMicroservices() must be called before app.listen() -> Option C
Quick Check:
Start microservices before HTTP listen [OK]
Hint: Call startAllMicroservices() before app.listen() [OK]
Common Mistakes:
Calling startAllMicroservices() after app.listen()
Adding await to connectMicroservice()
Thinking transport option is invalid
5. You want to build a NestJS hybrid app that handles HTTP requests and listens to RabbitMQ messages. Which steps correctly set up the microservice part?
hard
A. Use connectMicroservice({ transport: Transport.TCP }) and call startAllMicroservices() after app.listen()
B. Use createMicroservice({ transport: Transport.RMQ }) and call app.listen() before starting microservices
C. Add RabbitMQ config in AppModule imports and call app.listen() only
D. Use connectMicroservice({ transport: Transport.RMQ, options: { urls: ['amqp://localhost'], queue: 'main_queue' } }), then call startAllMicroservices() before app.listen()
Solution
Step 1: Choose correct microservice setup for RabbitMQ
connectMicroservice() with Transport.RMQ and proper options (urls, queue) is the correct way to add RabbitMQ microservice.
Step 2: Call startAllMicroservices() before app.listen()
Microservices must start before HTTP server listens to ensure both run properly.
Final Answer:
Use connectMicroservice({ transport: Transport.RMQ, options: { urls: ['amqp://localhost'], queue: 'main_queue' } }), then call startAllMicroservices() before app.listen() -> Option D
Quick Check:
connectMicroservice + RMQ options + startAllMicroservices before listen [OK]
Hint: Set RMQ options in connectMicroservice and start microservices first [OK]
Common Mistakes:
Using createMicroservice() which is not a NestFactory method
Calling app.listen() before starting microservices
Using wrong transport type for RabbitMQ
Not providing RabbitMQ connection options
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.