Class CommonInternalServiceConnectionPoolProperties

java.lang.Object
com.broadleafcommerce.common.extension.webclient.autoconfigure.CommonInternalServiceConnectionPoolProperties

@ConfigurationProperties("broadleaf.common.webclient.connection-pool") public class CommonInternalServiceConnectionPoolProperties extends Object

Configures the dedicated Reactor Netty connection pool backing internal service-to-service WebClient communication.

Without this pool, every HttpClient.create() in the JVM shares Reactor Netty's global HttpResources pool. That pool is anonymous and has metrics disabled, so there is no way to observe how saturated outbound connections are for a given service. Declaring an explicitly named pool is what makes the reactor.netty.connection.provider.* meters possible, since Reactor Netty tags those meters with the pool name.

Since:
MicroExtensionCommon 3.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default maximum number of pooled connections.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    boolean
     
    The interval at which the pool proactively evicts connections that are no longer usable, rather than waiting for them to be acquired again.
    int
    The maximum number of concurrent connections the pool will open before further acquisitions are queued.
    How long a connection may sit unused in the pool before it is evicted.
    The maximum absolute age of a pooled connection, after which it is evicted once its in-flight request completes.
    The name of the connection pool.
    The maximum number of requests that may be queued waiting for a connection.
    How long a request may wait for a connection once the pool is saturated before failing.
    int
     
    boolean
    Whether internal service-to-service WebClients should use a dedicated, named connection pool rather than Reactor Netty's global HttpResources pool.
    boolean
    Whether Reactor Netty should publish connection pool metrics for this pool.
    void
    setEnabled(boolean enabled)
    Whether internal service-to-service WebClients should use a dedicated, named connection pool rather than Reactor Netty's global HttpResources pool.
    void
    setEvictInBackground(Duration evictInBackground)
    The interval at which the pool proactively evicts connections that are no longer usable, rather than waiting for them to be acquired again.
    void
    setMaxConnections(int maxConnections)
    The maximum number of concurrent connections the pool will open before further acquisitions are queued.
    void
    setMaxIdleTime(Duration maxIdleTime)
    How long a connection may sit unused in the pool before it is evicted.
    void
    setMaxLifeTime(Duration maxLifeTime)
    The maximum absolute age of a pooled connection, after which it is evicted once its in-flight request completes.
    void
    setMetricsEnabled(boolean metricsEnabled)
    Whether Reactor Netty should publish connection pool metrics for this pool.
    void
    The name of the connection pool.
    void
    setPendingAcquireMaxCount(Integer pendingAcquireMaxCount)
    The maximum number of requests that may be queued waiting for a connection.
    void
    setPendingAcquireTimeout(Duration pendingAcquireTimeout)
    How long a request may wait for a connection once the pool is saturated before failing.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_CONNECTIONS

      public static final int DEFAULT_MAX_CONNECTIONS
      The default maximum number of pooled connections. This deliberately mirrors the formula Reactor Netty uses when it builds the global HttpResources HTTP pool (TcpResources.create), so that introducing a dedicated pool does not change the connection ceiling internal traffic has been running with.
  • Constructor Details

    • CommonInternalServiceConnectionPoolProperties

      public CommonInternalServiceConnectionPoolProperties()
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Whether internal service-to-service WebClients should use a dedicated, named connection pool rather than Reactor Netty's global HttpResources pool. Disabling this restores the pre-3.0.0 behavior, at the cost of losing connection pool metrics.
      Returns:
      whether the dedicated connection pool is used
    • getName

      public String getName()
      The name of the connection pool. This is emitted as the id tag on every reactor.netty.connection.provider.* meter, so it is what distinguishes this pool from any other pool in the same application.
      Returns:
      the name of the connection pool
    • isMetricsEnabled

      public boolean isMetricsEnabled()

      Whether Reactor Netty should publish connection pool metrics for this pool. When enabled, the following gauges are registered against Micrometer's global registry (which Spring Boot binds to the application's MeterRegistry by default, via management.metrics.use-global-registry):

      • reactor.netty.connection.provider.total.connections
      • reactor.netty.connection.provider.active.connections
      • reactor.netty.connection.provider.idle.connections
      • reactor.netty.connection.provider.pending.connections
      • reactor.netty.connection.provider.max.connections
      • reactor.netty.connection.provider.max.pending.connections
      • reactor.netty.connection.provider.pending.connections.time

      Each meter is tagged with id (the pool name) and remote.address. Meters are registered lazily, as connections to a given remote address are first established. Requires io.micrometer:micrometer-core on the classpath; if it is absent, metrics are skipped with a warning rather than failing startup.

      Returns:
      whether connection pool metrics are published
    • getMaxConnections

      public int getMaxConnections()

      The maximum number of concurrent connections the pool will open before further acquisitions are queued.

      This defaults to DEFAULT_MAX_CONNECTIONS in order to match the global HttpResources pool that this pool displaces. Note that this is not the same as ConnectionProvider.builder(name)'s own default, which is only twice the number of available processors (minimum 16) - a fraction of the 500 that internal service-to-service traffic has effectively been running with. Leaving this unset must not quietly shrink the ceiling, or a busy service would start queueing requests until they hit getPendingAcquireTimeout().

      MicroPM#6849 proposes lowering this to 350 on the grounds that only ~200 Tomcat worker threads can be initiating outbound requests anyway; that is a deliberate tuning decision and belongs to that work, not here.

      Returns:
      the maximum number of pooled connections
    • getMaxLifeTime

      public Duration getMaxLifeTime()
      The maximum absolute age of a pooled connection, after which it is evicted once its in-flight request completes. null leaves Reactor Netty's default in place (no limit, meaning keep-alive connections live indefinitely).
      Returns:
      the maximum lifetime of a pooled connection
    • getMaxIdleTime

      public Duration getMaxIdleTime()
      How long a connection may sit unused in the pool before it is evicted. null leaves Reactor Netty's default in place (no limit).
      Returns:
      the maximum idle time of a pooled connection
    • getPendingAcquireTimeout

      public Duration getPendingAcquireTimeout()
      How long a request may wait for a connection once the pool is saturated before failing. null leaves Reactor Netty's default in place (45 seconds).
      Returns:
      the maximum time spent waiting for a pooled connection
    • getPendingAcquireMaxCount

      public Integer getPendingAcquireMaxCount()
      The maximum number of requests that may be queued waiting for a connection. null leaves Reactor Netty's default in place (twice getMaxConnections()).
      Returns:
      the maximum number of queued connection acquisitions
    • getEvictInBackground

      public Duration getEvictInBackground()
      The interval at which the pool proactively evicts connections that are no longer usable, rather than waiting for them to be acquired again. null leaves Reactor Netty's default in place (background eviction disabled). Reactor Netty requires a value of at least 1 second when this is set.
      Returns:
      the background eviction interval
    • setEnabled

      public void setEnabled(boolean enabled)
      Whether internal service-to-service WebClients should use a dedicated, named connection pool rather than Reactor Netty's global HttpResources pool. Disabling this restores the pre-3.0.0 behavior, at the cost of losing connection pool metrics.
      Parameters:
      enabled - whether the dedicated connection pool is used
    • setName

      public void setName(String name)
      The name of the connection pool. This is emitted as the id tag on every reactor.netty.connection.provider.* meter, so it is what distinguishes this pool from any other pool in the same application.
      Parameters:
      name - the name of the connection pool
    • setMetricsEnabled

      public void setMetricsEnabled(boolean metricsEnabled)

      Whether Reactor Netty should publish connection pool metrics for this pool. When enabled, the following gauges are registered against Micrometer's global registry (which Spring Boot binds to the application's MeterRegistry by default, via management.metrics.use-global-registry):

      • reactor.netty.connection.provider.total.connections
      • reactor.netty.connection.provider.active.connections
      • reactor.netty.connection.provider.idle.connections
      • reactor.netty.connection.provider.pending.connections
      • reactor.netty.connection.provider.max.connections
      • reactor.netty.connection.provider.max.pending.connections
      • reactor.netty.connection.provider.pending.connections.time

      Each meter is tagged with id (the pool name) and remote.address. Meters are registered lazily, as connections to a given remote address are first established. Requires io.micrometer:micrometer-core on the classpath; if it is absent, metrics are skipped with a warning rather than failing startup.

      Parameters:
      metricsEnabled - whether connection pool metrics are published
    • setMaxConnections

      public void setMaxConnections(int maxConnections)

      The maximum number of concurrent connections the pool will open before further acquisitions are queued.

      This defaults to DEFAULT_MAX_CONNECTIONS in order to match the global HttpResources pool that this pool displaces. Note that this is not the same as ConnectionProvider.builder(name)'s own default, which is only twice the number of available processors (minimum 16) - a fraction of the 500 that internal service-to-service traffic has effectively been running with. Leaving this unset must not quietly shrink the ceiling, or a busy service would start queueing requests until they hit getPendingAcquireTimeout().

      MicroPM#6849 proposes lowering this to 350 on the grounds that only ~200 Tomcat worker threads can be initiating outbound requests anyway; that is a deliberate tuning decision and belongs to that work, not here.

      Parameters:
      maxConnections - the maximum number of pooled connections
    • setMaxLifeTime

      public void setMaxLifeTime(Duration maxLifeTime)
      The maximum absolute age of a pooled connection, after which it is evicted once its in-flight request completes. null leaves Reactor Netty's default in place (no limit, meaning keep-alive connections live indefinitely).
      Parameters:
      maxLifeTime - the maximum lifetime of a pooled connection
    • setMaxIdleTime

      public void setMaxIdleTime(Duration maxIdleTime)
      How long a connection may sit unused in the pool before it is evicted. null leaves Reactor Netty's default in place (no limit).
      Parameters:
      maxIdleTime - the maximum idle time of a pooled connection
    • setPendingAcquireTimeout

      public void setPendingAcquireTimeout(Duration pendingAcquireTimeout)
      How long a request may wait for a connection once the pool is saturated before failing. null leaves Reactor Netty's default in place (45 seconds).
      Parameters:
      pendingAcquireTimeout - the maximum time spent waiting for a pooled connection
    • setPendingAcquireMaxCount

      public void setPendingAcquireMaxCount(Integer pendingAcquireMaxCount)
      The maximum number of requests that may be queued waiting for a connection. null leaves Reactor Netty's default in place (twice getMaxConnections()).
      Parameters:
      pendingAcquireMaxCount - the maximum number of queued connection acquisitions
    • setEvictInBackground

      public void setEvictInBackground(Duration evictInBackground)
      The interval at which the pool proactively evicts connections that are no longer usable, rather than waiting for them to be acquired again. null leaves Reactor Netty's default in place (background eviction disabled). Reactor Netty requires a value of at least 1 second when this is set.
      Parameters:
      evictInBackground - the background eviction interval
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object