Skip to content

Commit

Permalink
Removed ReceiveBufferSize and SendBufferSize to improve message rates
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
MarcoZuiderwijkBS authored and lukebakken committed Nov 15, 2023
1 parent 739a46a commit b8f6832
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 1 addition & 3 deletions projects/RabbitMQ.Client/client/api/ConnectionFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public static ITcpClient DefaultSocketFactory(AddressFamily addressFamily)
{
var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)
{
NoDelay = true,
ReceiveBufferSize = 65536,
SendBufferSize = 65536
NoDelay = true
};
return new TcpClientAdapter(socket);
}
Expand Down
30 changes: 30 additions & 0 deletions projects/Unit/TestConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
//---------------------------------------------------------------------------

using System.Collections.Generic;
using System.Net.Sockets;
using RabbitMQ.Client.Exceptions;
using RabbitMQ.Client.Impl;
using Xunit;

namespace RabbitMQ.Client.Unit
Expand Down Expand Up @@ -69,6 +71,34 @@ public void TestProperties()
Assert.Equal(cf.Endpoint.MaxMessageSize, mms);
}

[Fact]
public void TestConnectionFactoryWithCustomSocketFactory()
{
const int bufsz = 1024;

ConnectionFactory cf = new()
{
SocketFactory = (AddressFamily af) =>
{
var socket = new Socket(af, SocketType.Stream, ProtocolType.Tcp)
{
SendBufferSize = bufsz,
ReceiveBufferSize = bufsz,
NoDelay = false
};
return new TcpClientAdapter(socket);
}
};

ITcpClient c = cf.SocketFactory(AddressFamily.InterNetwork);
Assert.IsType<TcpClientAdapter>(c);
TcpClientAdapter tcpClientAdapter = (TcpClientAdapter)c;
Socket s = tcpClientAdapter.Client;
Assert.Equal(bufsz, s.ReceiveBufferSize);
Assert.Equal(bufsz, s.SendBufferSize);
Assert.False(s.NoDelay);
}

[Fact]
public void TestCreateConnectionUsesSpecifiedPort()
{
Expand Down

0 comments on commit b8f6832

Please sign in to comment.