Class CommonExternalServiceClientConnectorFactory

java.lang.Object
com.broadleafcommerce.common.extension.webclient.autoconfigure.external.CommonExternalServiceClientConnectorFactory

public class CommonExternalServiceClientConnectorFactory extends Object

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:

  1. 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.).
  2. 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 Details

    • CommonExternalServiceClientConnectorFactory

      public CommonExternalServiceClientConnectorFactory(@NonNull CommonExternalServiceConnectionPoolTemplateProperties poolProperties)
      Constructs a new CommonExternalServiceClientConnectorFactory with the specified global default properties.
      Parameters:
      poolProperties - the global defaults and pool tuning parameters applied to all built connection pools
  • Method Details

    • unpooled

      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 be null, falling back to defaults)
      Returns:
      a safe fallback, unpooled CommonExternalServiceClientConnectorFactory instance
    • createConnector

      public org.springframework.http.client.reactive.ClientHttpConnector createConnector(@NonNull String poolName)
      Creates a ClientHttpConnector instance 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 a ClientHttpConnector instance 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 pool
      connectionProviderCustomizer - an optional customizer to apply additional configurations to the connection pool builder
      clientCustomizer - 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 an HttpClient instance bound to a named connection pool using default global connection pool configurations. Takes a ConnectionProvider.Builder for additional custom pool builder configurations.
      Parameters:
      poolName - the unique name to identify and tag the connection pool
      connectionProviderCustomizer - an optional customizer to apply additional configurations to the ConnectionProvider.Builder
      Returns:
      a configured HttpClient
    • getPoolProperties

      @NonNull protected CommonExternalServiceConnectionPoolTemplateProperties getPoolProperties()
    • isUnpooled

      protected boolean isUnpooled()