Prefetch (QoS) 限制消费者一次可以持有多少条未确认的消息 — 控制工作分配,防止一个消费者被压垮而其他消费者处于空闲状态。这对公平、高效的消息处理至关重要。
Prefetch的作用
PREFETCH (QoS - prefetch count) → limits the number of UNACKNOWLEDGED messages a consumer
can have at once:
→ without it → RabbitMQ may dispatch many messages to one consumer (it grabs a batch)
→ with prefetch=N → a consumer gets at most N unacked messages at a time (must ack to get more)
→ controls how messages are distributed and how much a consumer buffers
Prefetch为什么重要(公平分配)
Without prefetch (or too high):
✗ one consumer might grab MANY messages (even slow-to-process ones) while others sit idle
→ unfair distribution, poor load balancing
With appropriate prefetch:
✓ FAIR DISPATCH → messages distributed more evenly (a busy consumer doesn't hoard messages)
✓ a slow consumer holds fewer; a fast one gets more (work flows to available consumers)
→ prefetch enables fair, efficient work distribution among consumers
