This topic describes the concepts of connection and channel in ApsaraMQ for RabbitMQ and provides notes on their usage.
Connection
A connection refers to a physical Transmission Control Protocol (TCP) connection. Connections are established between applications and ApsaraMQ for RabbitMQ. Connections can be used to support underlying network tasks, such as authentication, IP address resolution, and routing. The establishment of a connection between an application and ApsaraMQ for RabbitMQ requires about 15 TCP packets for interaction. This consumes a large number of network resources and ApsaraMQ for RabbitMQ resources. A large number of connections may cause great pressure on ApsaraMQ for RabbitMQ or even trigger protection against SYN flood attacks. In this case, ApsaraMQ for RabbitMQ may fail to respond, and your business is affected.
Channel
A channel refers to a virtual connection that is established based on a physical TCP connection. All AMQP-based operations are performed over the channels of a connection between an application and ApsaraMQ for RabbitMQ. For example, queues are created over channels, and messages are sent and received over channels. Each connection can have multiple channels. Channels are dependent on connections. After a connection is closed, all channels of the connection are also closed. If you want to connect a large number of applications to ApsaraMQ for RabbitMQ, we recommend that you establish multiple channels for one connection instead of establishing a large number of connections. This reduces the usage of network resources and ApsaraMQ for RabbitMQ resources.
Usage notes
Use persistent connections. Do not frequently open or close a connection. You can frequently open or close a channel. For information about the limits on the API operations that are called to open connections and channels on an instance, see Limits.
If the number of connections is small and the amount of data consumed is large, consumption skew may occur. To prevent the issue, you can increase the number of connections that each consumer establishes or the number of consumers while ensuring that the number of connections that each consumer establishes is the same. We recommend that the total number of connections that all consumers establish be greater than 30.
Multiple processes can share a connection. When multiple processes share a connection, do not frequently open or close the connection. Otherwise, the
ChannelNotFind
error may occur.Producers and consumers use different connections to produce and consume messages.