Transport & Patterns

Preview — 3 of 10 questions

Which factory method bootstraps a standalone NestJS microservice (no HTTP server)?

javascript
import { NestFactory } from '@nestjs/core';
import { Transport, MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.TCP,
    options: { host: '0.0.0.0', port: 3001 },
  });
  await app.listen();
}
bootstrap();
ANestFactory.createMicroservice()
BNestFactory.create()
CNestFactory.createApplicationContext()
DMicroserviceFactory.start()

Which of the following is NOT a built-in value of the Transport enum?

javascript
import { Transport } from '@nestjs/microservices';

Transport.TCP;
Transport.REDIS;
Transport.NATS;
Transport.RMQ;
Transport.KAFKA;
Transport.GRPC;
// Transport.GRAPHQL  // ❌ does not exist
ATransport.TCP
BTransport.KAFKA
CTransport.GRAPHQL
DTransport.RMQ

Which decorator handles a request-response message and returns a value to the caller?

javascript
import { Controller } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices';

@Controller()
export class MathController {
  @MessagePattern({ cmd: 'sum' })
  sum(@Payload() nums: number[]): number {
    return nums.reduce((a, b) => a + b, 0); // returned to caller
  }
}
A@MessagePattern()
B@EventPattern()
C@Get()
D@Subscribe()

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.