技术笔记
- 多 Channel 复用一个 Connection
- understand what a queue is and how it works
Before you consume from or publish to Rabbit, you first have to connect to it. By connecting, you’re creating a TCP connection between your app and the Rabbit bro- ker. Once the TCP connection is open (and you’re authenticated), your app then cre- ates an AMQP channel. This channel is a virtual connection inside the “real” TCP connection, and it’s over the channel that you issue AMQP commands. Every channel has a unique ID assigned to it (your AMQP library of choice will handle remembering the ID for you). Whether you’re publishing a message, subscribing to a queue, or receiving a message, it’s all done over a channel. Why do we need channels, you might ask? Why not just issue AMQP commands directly over the TCP connection? The main reason is because setting up and tearing down TCP sessions is expensive for an operating system.
Conceptually, there are three parts to any successful routing of an AMQP message: exchanges, queues, and bindings. **The exchanges are where producers publish their messages, queues are where the messages end up and are received by consumers, and bindings are how the messages get routed from the exchange to particular queues. ** Before you get to examine exchanges and bindings, you need to understand what a queue is and how it works.