AMQP 0-9-1中在Connection中打开多个channel以复用Connection。
通道存在于连接上下文中,通道之间互相隔离,当连接关闭,连接上打开的通道也会被关闭。
客户端和broker之间使用channel id区分通道
Resource Usage
客户端:部分内存
broker:部分内存+erlang进程
Maximum Number of Channels per Connection
连接上可以同时打开的最大通道数由客户端和服务器在连接时协商。该值对于 RabbitMQ 和客户端库都是可配置的。
- 每个链接最大通道数取两者中最小值
- 创建连接时,client设置的最大通道数不能大于服务端,否则连接创建失败
- 连接创建后,创建通道时超出限制会导致报错并关闭连接
server
# no more 100 channels can be opened on a connection at the same time
channel_max = 100
client
ConnectionFactory cf = new ConnectionFactory();
// Ask for up to 32 channels per connection. Will have an effect as long as the server is configured
// to use a higher limit, otherwise the server's limit will be used.
cf.setRequestedChannelMax(32);
Safety