Redis, RabbitMQ & More

Preview — 3 of 10 questions

How do you run an HTTP server and a microservice listener in the same NestJS process?

javascript
const app = await NestFactory.create(AppModule);
app.connectMicroservice<MicroserviceOptions>({
  transport: Transport.TCP,
  options: { port: 3001 },
});
await app.startAllMicroservices();
await app.listen(3000); // HTTP + microservice in one process
ACall NestFactory.createMicroservice() twice
BCreate the HTTP app with NestFactory.create(), call app.connectMicroservice(options), then app.startAllMicroservices() and app.listen(port)
CIt is impossible — they must be separate processes
DSet transport: 'hybrid' in forRoot()

Which options correctly configure the Redis transport?

javascript
ClientsModule.register([
  {
    name: 'NOTIFICATIONS',
    transport: Transport.REDIS,
    options: { host: 'localhost', port: 6379, retryAttempts: 5, retryDelay: 1000 },
  },
]);
A{ servers: ['redis://localhost'] }
B{ brokers: ['localhost:6379'] }
C{ queue: 'redis_queue' }
D{ host: 'localhost', port: 6379, retryAttempts: 5, retryDelay: 1000 }

In the RabbitMQ transport, what does setting noAck: false (with queue) require you to do?

javascript
@MessagePattern('order.process')
process(@Payload() data: any, @Ctx() ctx: RmqContext) {
  const channel = ctx.getChannelRef();
  const original = ctx.getMessage();
  // ... work ...
  channel.ack(original); // required when noAck: false
}
ANothing changes — messages auto-acknowledge
BYou must manually acknowledge each message via the RmqContext channel, otherwise unacked messages are redelivered
CIt disables the queue entirely
DIt switches to fire-and-forget only

Sign up free to play

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