Skip to content

Commit

Permalink
Add Log Messages when Configuring Reactor Netty ConnectionProvider (#…
Browse files Browse the repository at this point in the history
…32826)

Add Log Messages when Configuring Reactor Netty ConnectionProvider
  • Loading branch information
alzimmermsft committed Jan 9, 2023
1 parent a7e0fa5 commit 432748c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public com.azure.core.http.HttpClient build() {
*/
public NettyAsyncHttpClientBuilder connectionProvider(ConnectionProvider connectionProvider) {
// Enables overriding the default reactor-netty connection/channel pool.
if (connectionProvider != null) {
LOGGER.verbose("Setting ConnectionProvider for the Reactor Netty HttpClient. Please be aware of the "
+ "differences in runtime behavior when creating a default Reactor Netty HttpClient vs an HttpClient"
+ "with a specified ConnectionProvider. For more details see "
+ "https://aka.ms/azsdk/java/docs/configure-httpclient.");
}

this.connectionProvider = connectionProvider;
return this;
}

NettyAsyncHttpClientBuilder connectionProviderInternal(ConnectionProvider connectionProvider) {
this.connectionProvider = connectionProvider;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.core.http.HttpClientProvider;
import com.azure.core.util.Configuration;
import com.azure.core.util.HttpClientOptions;
import com.azure.core.util.logging.ClientLogger;
import reactor.netty.resources.ConnectionProvider;

/**
Expand All @@ -18,6 +19,8 @@ public final class NettyAsyncHttpClientProvider implements HttpClientProvider {
private final boolean enableHttpClientSharing;
private static final int DEFAULT_MAX_CONNECTIONS = 500;

private static final ClientLogger LOGGER = new ClientLogger(NettyAsyncHttpClientProvider.class);

// Enum Singleton Pattern
private enum GlobalNettyHttpClient {
HTTP_CLIENT(new NettyAsyncHttpClientBuilder().build());
Expand Down Expand Up @@ -73,6 +76,8 @@ public HttpClient createInstance(HttpClientOptions clientOptions) {
// Only configure the maximum connections if it has been set in the options.
Integer maximumConnectionPoolSize = clientOptions.getMaximumConnectionPoolSize();
if (maximumConnectionPoolSize != null && maximumConnectionPoolSize > 0) {
LOGGER.verbose("Setting Reactor Netty ConnectionProvider's maximum connections to "
+ maximumConnectionPoolSize + ".");
connectionProviderBuilder.maxConnections(maximumConnectionPoolSize);
} else {
// reactor-netty (as of version 1.0.13) uses different default values for maxConnections when creating
Expand All @@ -89,7 +94,7 @@ public HttpClient createInstance(HttpClientOptions clientOptions) {
connectionProviderBuilder.maxConnections(DEFAULT_MAX_CONNECTIONS);
}

builder = builder.connectionProvider(connectionProviderBuilder.build());
builder = builder.connectionProviderInternal(connectionProviderBuilder.build());

return builder.build();
}
Expand Down

0 comments on commit 432748c

Please sign in to comment.