Class CommonExternalServiceClientConnectorFactory
Centralized factory for building isolated, named HttpClient and
ClientHttpConnector instances dedicated to external third-party service communication.
Architectural Resource Isolation
The setup for external third-party service communication is kept separate from
internal service-to-service communication for
two primary reasons:
- External connections typically require different default configurations than internal setups (e.g., SSL is usually enabled instead of disabled, special connection timeouts may be needed to account for cloud gateway timeouts, etc.).
- While webclients for internal service communication share a single global pool, integrations with external services may require independent pools to ensure they do not exhaust each other's resources in the case of starvation, high latency, or outages in external dependencies.
In this sense, the factory for external clients acts as a template to bootstrap a reasonable
configuration rather than serving as an actual centralized connection pool instance (though such
an instance is still made available via
CommonExternalServiceConnectionAutoConfiguration.commonExtlSvcClientConnector(com.broadleafcommerce.common.extension.webclient.autoconfigure.external.CommonExternalServiceClientConnectorFactory, com.broadleafcommerce.common.extension.webclient.autoconfigure.external.CommonExternalServiceDefaultConnectionPoolProperties)). The
factory provides the ability to configure reasonable defaults in a single centralized component,
making it easy to apply global changes that affect all external clients simultaneously.
Additionally, this setup is designed so that consumers can customize the output of the factory to
override settings as needed.
- Since:
- MicroExtensionCommon 3.0.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCommonExternalServiceClientConnectorFactory(CommonExternalServiceConnectionPoolTemplateProperties poolProperties) Constructs a newCommonExternalServiceClientConnectorFactorywith the specified global default properties. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.client.reactive.ClientHttpConnectorcreateConnector(String poolName) Creates aClientHttpConnectorinstance bound to a named connection pool with default settings applied.org.springframework.http.client.reactive.ClientHttpConnectorcreateConnector(String poolName, Consumer<reactor.netty.resources.ConnectionProvider.Builder> connectionProviderCustomizer, UnaryOperator<reactor.netty.http.client.HttpClient> clientCustomizer, Consumer<io.netty.handler.ssl.SslContextBuilder> sslCustomizer) Creates aClientHttpConnectorinstance bound to a named connection pool with the appropriate SSL policy, client, and connection configurations applied.protected reactor.netty.http.client.HttpClientcreateHttpClient(String poolName, Consumer<reactor.netty.resources.ConnectionProvider.Builder> connectionProviderCustomizer) Creates anHttpClientinstance bound to a named connection pool using default global connection pool configurations.protected booleanunpooled(CommonExternalServiceConnectionPoolTemplateProperties poolProperties) Static factory method to instantiate a safe fallback factory for sliced tests.
-
Constructor Details
-
CommonExternalServiceClientConnectorFactory
public CommonExternalServiceClientConnectorFactory(@NonNull CommonExternalServiceConnectionPoolTemplateProperties poolProperties) Constructs a newCommonExternalServiceClientConnectorFactorywith the specified global default properties.- Parameters:
poolProperties- the global defaults and pool tuning parameters applied to all built connection pools
-
-
Method Details
-
unpooled
public static CommonExternalServiceClientConnectorFactory unpooled(@Nullable CommonExternalServiceConnectionPoolTemplateProperties poolProperties) Static factory method to instantiate a safe fallback factory for sliced tests. Guaranteed immune to NullPointerExceptions in environments where properties are not loaded.- Parameters:
poolProperties- the global pool tuning parameters (may benull, falling back to defaults)- Returns:
- a safe fallback, unpooled
CommonExternalServiceClientConnectorFactoryinstance
-
createConnector
public org.springframework.http.client.reactive.ClientHttpConnector createConnector(@NonNull String poolName) Creates aClientHttpConnectorinstance bound to a named connection pool with default settings applied.- Parameters:
poolName- the unique name to identify and tag the connection pool- Returns:
- a configured ClientHttpConnector
- See Also:
-
createConnector
public org.springframework.http.client.reactive.ClientHttpConnector createConnector(@NonNull String poolName, @Nullable Consumer<reactor.netty.resources.ConnectionProvider.Builder> connectionProviderCustomizer, @Nullable UnaryOperator<reactor.netty.http.client.HttpClient> clientCustomizer, @Nullable Consumer<io.netty.handler.ssl.SslContextBuilder> sslCustomizer) Creates aClientHttpConnectorinstance bound to a named connection pool with the appropriate SSL policy, client, and connection configurations applied.- Parameters:
poolName- the unique name to identify and tag the connection poolconnectionProviderCustomizer- an optional customizer to apply additional configurations to the connection pool builderclientCustomizer- an optional customizer to apply additional configurations to the HttpClient (timeouts, proxies, etc.)sslCustomizer- an optional customizer to build a custom SSL context (e.g., mTLS). Note: If provided, this customizer takes full control of SSL configuration; global property overrides (such as disabling SSL verification) are ignored.- Returns:
- a configured ClientHttpConnector
- See Also:
-
createHttpClient
protected reactor.netty.http.client.HttpClient createHttpClient(@NonNull String poolName, @Nullable Consumer<reactor.netty.resources.ConnectionProvider.Builder> connectionProviderCustomizer) Creates anHttpClientinstance bound to a named connection pool using default global connection pool configurations. Takes aConnectionProvider.Builderfor additional custom pool builder configurations.- Parameters:
poolName- the unique name to identify and tag the connection poolconnectionProviderCustomizer- an optional customizer to apply additional configurations to theConnectionProvider.Builder- Returns:
- a configured HttpClient
-
getPoolProperties
-
isUnpooled
protected boolean isUnpooled()
-