Skip to content

Commit 7b35960

Browse files
committed
Reduce channel max to 2047
Max number of channels has been reduced from unlimited to 2048 as of RabbitMQ 3.7.5. This is to avoid applications that leak channels to starve the broker resources. 2048 has been picked up scientifically: more than 1 K channels per connection is hard to justify, so we doubled the value to leave existing applications some room. Java client uses 2047 as it uses channel 0 for negotiation and error handling. Part of rabbitmq/rabbitmq-server#1593. Fixes #366
1 parent 0427cfd commit 7b35960

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public class ConnectionFactory implements Cloneable {
6363
/** Default virtual host */
6464
public static final String DEFAULT_VHOST = "/";
6565
/** Default maximum channel number;
66-
* zero for unlimited */
67-
public static final int DEFAULT_CHANNEL_MAX = 0;
66+
* 2047 because it's 2048 on the server side minus channel 0,
67+
* which each connection uses for negotiation
68+
* and error communication */
69+
public static final int DEFAULT_CHANNEL_MAX = 2047;
6870
/** Default maximum frame size;
6971
* zero means no limit */
7072
public static final int DEFAULT_FRAME_MAX = 0;

src/test/java/com/rabbitmq/client/test/ChannelNumberAllocationTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,10 @@ public int compare(Channel x, Channel y){
119119
assertNotNull(connection.createChannel(5));
120120
assertNotNull(connection.createChannel(1));
121121
}
122+
123+
@Test public void channelMaxIs2047() {
124+
int channelMaxServerSide = 2048;
125+
int defaultChannelCount = 1;
126+
assertEquals(channelMaxServerSide - defaultChannelCount, connection.getChannelMax());
127+
}
122128
}

0 commit comments

Comments
 (0)