Backpressure is a common problem in Pub/Sub systems. It happens when messages are being published to a queue faster than they can be consumed. This leads to a growing queue size, which can eventually cause the system to run out of memory or disk space.
Let's add a feature to spam absurd amounts of game logs... for science. We'll use this feature to demonstrate backpressure.
Because our game_logs queue is listening for messages with the routing key game_logs.*, the server will receive messages from all players.
await ch.prefetch(1);
This tells RabbitMQ to only deliver one unacknowledged message at a time. It waits for an ack before sending the next one. That way, the server processes messages strictly one at a time, and we can finally see the queue grow. (We will dive deeper into ch.prefetch in an upcoming lesson.)
After publishing a large batch, refresh the page before running or submitting the tests to make sure the queue metrics were updated.
Run and submit the CLI tests with the queue still mostly full (thousands of messages).
In the next lesson, we'll empty the queue.
If messages_ready is set to 0, try any of the following:
rabbitmq container. Make sure the peril_direct and peril_topic exchanges are there (they should be if you use the npm scripts) and restart the server to create the game_logs queue.