在RabbitMQ中,connection是与broker的TCP连接,而channel是connection内的轻量级虚拟连接。正确使用channels(而不是许多connections)对效率很重要,是常见的最佳实践。
Connections与channels对比
CONNECTION → a TCP connection to the RabbitMQ broker:
→ relatively HEAVY (a real network connection, with overhead to establish/maintain)
CHANNEL → a lightweight, virtual connection MULTIPLEXED over a single TCP connection:
→ many channels share one connection → lightweight; most operations happen on channels
→ publishing, consuming, declaring queues → done via channels
→ one connection can have MANY channels (multiplexing reduces TCP overhead)
