Beyond first in first out
A plain queue is first in first out, so a flood of low value messages can delay an urgent one stuck behind them. A priority queue lets the broker serve higher priority messages first regardless of arrival order.
How brokers implement it
- Some brokers support a priority field per message and a single queue that always pops the highest priority ready item.
- Others use multiple queues, one per priority level, and consumers drain the high priority queue before the low one. This is simpler and easier to monitor.
The starvation risk
Strict priority can starve low priority work: if high priority traffic never stops, low priority messages wait forever. Common fixes:
- Weighted draining so consumers take, say, three high then one low message.
- Aging, where a message gains priority the longer it waits, eventually guaranteeing service.
Key idea
A priority queue serves urgent messages first but needs weighting or aging so lower priority work is not starved.