Redis, RabbitMQ & More — Series 2

Preview — 3 of 10 questions

What does prefetchCount: 10 control?

javascript
{
  transport: Transport.RMQ,
  options: {
    urls: ['amqp://rabbit:5672'],
    queue: 'orders',
    noAck: false,
    prefetchCount: 10,
    queueOptions: { durable: true },
  },
}
AThe number of messages the broker keeps in the queue before rejecting publishers
BHow many times a message is redelivered before being discarded
CHow many unacknowledged messages the broker will deliver to this consumer at once — bounding in-flight work, so a slow consumer does not accumulate hundreds of messages it cannot process while other consumers sit idle
DThe batch size handed to a single handler invocation

What does nack(message, false, false) do?

javascript
@EventPattern('order.created')
async handle(@Payload() data: OrderCreated, @Ctx() context: RmqContext) {
  const channel = context.getChannelRef();
  const message = context.getMessage();
  try {
    await this.process(data);
    channel.ack(message);
  } catch (err) {
    channel.nack(message, false, false);
  }
}
AIt rejects this one message without requeueing it, so the queue's dead-letter configuration takes over and the message is routed to the DLQ for inspection instead of looping forever
BIt requeues the message immediately for another attempt
CIt acknowledges the message but records a failure metric
DIt rejects every unacknowledged message held by this consumer

What happens under Transport.REDIS (pub/sub), and what would happen with RabbitMQ?

javascript
Consumer restarts for 30 seconds during a deploy.
Ten `order.created` events are published in that window.
ABoth hold the events until the consumer returns
BRedis buffers them per channel with a default retention of one hour
CRedis replays them on reconnect, provided the client id is stable
DRedis pub/sub delivers only to subscribers connected at publish time, so all ten events are lost; a durable RabbitMQ queue retains them and delivers on reconnect — which is why pub/sub suits ephemeral notifications and a queue suits work that must not be dropped

Sign up free to play

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