Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

34%
RabbitMQ & AMQP (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How do Priority Queues (`x-max-priority`) work in RabbitMQ?

senior LevelCode ExampleSystem DesignRabbitMQMicroservices

In Simple Words: RabbitMQ allows queues to prioritize urgent messages over standard messages:

javascript
// Declare queue with max priority levels 1-10
await channel.assertQueue('job_queue', {
  arguments: { 'x-max-priority': 10 }
});

// Publish high-priority VIP message
channel.publish('', 'job_queue', Buffer.from('VIP order'), { priority: 9 });

// Publish normal message
channel.publish('', 'job_queue', Buffer.from('Regular order'), { priority: 1 });

When a consumer requests a message, RabbitMQ serves priority 9 messages ahead of priority 1 messages, even if the priority 1 messages arrived earlier.