Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RabbitMQ.Stream.Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public string ClientProvidedName
public SslOption Ssl { get; set; } = new SslOption();

/// <summary>
/// TCP socket options (buffer sizes, NoDelay, KeepAlive, Linger). When null, library defaults are used.
/// TCP socket options (buffer sizes, NoDelay, Linger). When null, library defaults are used.
/// </summary>
public SocketOptions SocketOptions { get; set; }

Expand Down
2 changes: 0 additions & 2 deletions RabbitMQ.Stream.Client/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ private static void ApplySocketOptions(Socket socket, SocketOptions options)
socket.NoDelay = true;
socket.SendBufferSize *= SocketOptions.DefaultBufferSizeMultiplier;
socket.ReceiveBufferSize *= SocketOptions.DefaultBufferSizeMultiplier;
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
return;
}

socket.NoDelay = options.NoDelay;
socket.SendBufferSize = options.SendBufferSize ?? socket.SendBufferSize * SocketOptions.DefaultBufferSizeMultiplier;
socket.ReceiveBufferSize = options.ReceiveBufferSize ?? socket.ReceiveBufferSize * SocketOptions.DefaultBufferSizeMultiplier;
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, options.KeepAlive);
if (options.LingerOption != null)
{
socket.LingerState = options.LingerOption;
Expand Down
2 changes: 1 addition & 1 deletion RabbitMQ.Stream.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ RabbitMQ.Stream.Client.RoutingStrategyType
RabbitMQ.Stream.Client.RoutingStrategyType.Hash = 0 -> RabbitMQ.Stream.Client.RoutingStrategyType
RabbitMQ.Stream.Client.RoutingStrategyType.Key = 1 -> RabbitMQ.Stream.Client.RoutingStrategyType
RabbitMQ.Stream.Client.SocketOptions
RabbitMQ.Stream.Client.SocketOptions.SocketOptions() -> void
RabbitMQ.Stream.Client.SocketOptions.KeepAlive.get -> bool
RabbitMQ.Stream.Client.SocketOptions.KeepAlive.set -> void
RabbitMQ.Stream.Client.SocketOptions.SocketOptions() -> void
RabbitMQ.Stream.Client.SocketOptions.LingerOption.get -> System.Net.Sockets.LingerOption
RabbitMQ.Stream.Client.SocketOptions.LingerOption.set -> void
RabbitMQ.Stream.Client.SocketOptions.NoDelay.get -> bool
Expand Down
13 changes: 11 additions & 2 deletions RabbitMQ.Stream.Client/SocketOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// 2.0, and the Mozilla Public License, version 2.0.
// Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

using System;
using System.Net.Sockets;

namespace RabbitMQ.Stream.Client
{
/// <summary>
/// Configurable TCP socket options for a connection. Use this to tune buffer sizes,
/// Nagle's algorithm, linger on close, and TCP keep-alive.
/// Nagle's algorithm, and linger on close.
/// </summary>
public class SocketOptions
{
Expand All @@ -35,8 +36,16 @@ public class SocketOptions
public bool NoDelay { get; set; } = true;

/// <summary>
/// Enable TCP keep-alive to detect dead connections. Default is true.
/// Deprecated TCP keep-alive option.
/// </summary>
/// <remarks>
/// This property is intentionally ignored by the connection implementation and does not
/// enable TCP keep-alive on the underlying socket. The client library automatically
/// reconnects in case of connection failures, so explicit TCP keep-alive is not required.
/// The property is retained only for backward compatibility and to avoid a breaking
/// change in the public API; new code should not rely on it.
/// </remarks>
[Obsolete("KeepAlive is not needed since the library will automatically reconnect in case of connection failure.")]
public bool KeepAlive { get; set; } = true;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion RabbitMQ.Stream.Client/StreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal void Validate()

/// <summary>
/// See <see cref="SocketOptions"/> for configurable TCP socket options for a connection. Use this to tune buffer sizes,
/// Nagle's algorithm, linger on close, and TCP keep-alive.
/// Nagle's algorithm, and linger on close.
/// </summary>
public SocketOptions SocketOptions { get; set; } = null;

Expand Down
5 changes: 2 additions & 3 deletions Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,15 @@ public async Task ConnectWithDifferentSocketOptions()
{
SocketOptions = new SocketOptions
{
KeepAlive = true,
NoDelay = true,
ReceiveBufferSize = 1024 * 64,
SendBufferSize = 1024 * 64,
}
};
var client = await Client.Create(clientParameters);
Assert.NotNull(client);
await client.Close("done");

await client.Close("done");
var clientParameters1 = new ClientParameters
{
SocketOptions = new SocketOptions
Expand Down
14 changes: 14 additions & 0 deletions Tests/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,5 +504,19 @@ public TestLookupLocatorStrategy(int maxAttempts, TimeSpan delay)
public int MaxAttempts { get; init; }
public TimeSpan Delay { get; }
}

[Fact]
public async Task UseDnsEndpointShouldWork()
{
var config = new StreamSystemConfig()
{
Endpoints = new List<EndPoint> { new DnsEndPoint("localhost", 5552) }
};
var system = await StreamSystem.Create(config);
Assert.False(system.IsClosed);
await system.Close();
Assert.True(system.IsClosed);

Comment thread
Gsantomaggio marked this conversation as resolved.
}
}
}
4 changes: 2 additions & 2 deletions docs/ReliableClient/BestPracticesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This source code is dual-licensed under the Apache License, version
// This source code is dual-licensed under the Apache License, version
// 2.0, and the Mozilla Public License, version 2.0.
// Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

Expand Down Expand Up @@ -110,7 +110,7 @@ public static async Task Start(Config config)
// you can change them if you want to optimize the performance of the producer and consumer.
// SocketOptions = new SocketOptions()
// {
// // KeepAlive = true,
// // NoDelay = true,
//
// },
ConnectionPoolConfig = new ConnectionPoolConfig()
Expand Down
1 change: 0 additions & 1 deletion docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ Default is `null` with the default values:
socket.NoDelay = true;
socket.SendBufferSize *= SocketOptions.DefaultBufferSizeMultiplier;
socket.ReceiveBufferSize *= SocketOptions.DefaultBufferSizeMultiplier;
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
```

[[connection-pool]]
Expand Down
Loading