Skip to content

Commit b2586ed

Browse files
authored
Merge pull request #1415 from rabbitmq/rabbitmq-dotnet-client-1414
Removed ReceiveBufferSize and SendBufferSize to improve message rates
2 parents 739a46a + b8f6832 commit b2586ed

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

projects/RabbitMQ.Client/client/api/ConnectionFactoryBase.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public static ITcpClient DefaultSocketFactory(AddressFamily addressFamily)
5151
{
5252
var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)
5353
{
54-
NoDelay = true,
55-
ReceiveBufferSize = 65536,
56-
SendBufferSize = 65536
54+
NoDelay = true
5755
};
5856
return new TcpClientAdapter(socket);
5957
}

projects/Unit/TestConnectionFactory.cs

+30
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System.Collections.Generic;
33+
using System.Net.Sockets;
3334
using RabbitMQ.Client.Exceptions;
35+
using RabbitMQ.Client.Impl;
3436
using Xunit;
3537

3638
namespace RabbitMQ.Client.Unit
@@ -69,6 +71,34 @@ public void TestProperties()
6971
Assert.Equal(cf.Endpoint.MaxMessageSize, mms);
7072
}
7173

74+
[Fact]
75+
public void TestConnectionFactoryWithCustomSocketFactory()
76+
{
77+
const int bufsz = 1024;
78+
79+
ConnectionFactory cf = new()
80+
{
81+
SocketFactory = (AddressFamily af) =>
82+
{
83+
var socket = new Socket(af, SocketType.Stream, ProtocolType.Tcp)
84+
{
85+
SendBufferSize = bufsz,
86+
ReceiveBufferSize = bufsz,
87+
NoDelay = false
88+
};
89+
return new TcpClientAdapter(socket);
90+
}
91+
};
92+
93+
ITcpClient c = cf.SocketFactory(AddressFamily.InterNetwork);
94+
Assert.IsType<TcpClientAdapter>(c);
95+
TcpClientAdapter tcpClientAdapter = (TcpClientAdapter)c;
96+
Socket s = tcpClientAdapter.Client;
97+
Assert.Equal(bufsz, s.ReceiveBufferSize);
98+
Assert.Equal(bufsz, s.SendBufferSize);
99+
Assert.False(s.NoDelay);
100+
}
101+
72102
[Fact]
73103
public void TestCreateConnectionUsesSpecifiedPort()
74104
{

0 commit comments

Comments
 (0)