javaopensearchapache-httpcomponentsapache-httpclient-5.x

What is the difference between different apache-httpclient5 setup config provided by Apache HttpClient 5?


There are bunch of config provided by Apache HttpClient5 to modify how you use the client. But, these seems to be the most important: RequestConfig, and CloseableHttpAsyncClient, which includes IOReactorConfig and PoolingAsyncClientConnectionManager, which then includes ConnectionConfig. Here is the hierarchy of how I list them and what I think they mean based on the information I have found:

  1. RequestConfig: Configure the request made by the http client.
    • setConnectionRequestTimeout(Timeout): Timeout for the request made by the http client to get a connection from the connection pool.
    • setConnectTimeout(Timeout): Timeout for the request made by the http client to get a connection from the host.
    • setResponseTimeout(Timeout): Timeout for the request made by the http client to get a response from the host.
    • setConnectionKeepAlive(TimeValue): Timeout for the active connection to the host when not set via Keep-Alive response header.
  2. CloseableHttpAsyncClient: Configure the http client.
    • evictIdleConnections(TimeValue): Evict idle connections from the connection pool after the set time.
    • evictExpiredConnections(): If set to true, evict expired connections from the connection pool after some time.
    • setIOReactorConfig(IOReactorConfig): Configure the I/O Reactor that manages I/O requests made by the http client.
      • setSoTimeout(Timeout): Socket timeout for I/O requests made by the http client. Or maximum time for a blocked operation to finish its operation before throwing SocketTimeoutException.
      • setSoKeepAlive(boolean): Something will send requests to detect broken or idle connections.
      • setIoThreadCount(int): Number of threads used by the I/O Reactor.
      • setSelectInterval(TimeValue): Time interval when I/O Reactor checks for socket timeout or some session requests.
    • setConnectionManager(PoolingAsyncClientConnectionManager): Connection Manager that manages the connection pool used by the http client.
      • setMaxConnTotal(int): Maximum threads in the connection pool.
      • setDefaultConnectionConfig(ConnectionConfig): Connection Manager additional configuration.
        • setConnectTimeout(Timeout): No idea what this is. This might be similar to either RequestConfig setConnectionRequestTimeout() or setConnectTimeout(), or might be different all together.
        • setValidateAfterInactivity(TimeValue): Time period after which the active connections to the host needs to be validated if they are broken or stale.
        • setSocketTimeout(Timeout): No idea what this is. This might be similar to IOReactorConfig setSoTimeout(), or might be completely different.
        • setTimeToLive(TimeValue): TTL for a connection in the connection pool.

I am not sure how are these related or different from each other. Can anyone provide an explanation if my understanding of them are incorrect or how they are related, and how I can use them in my services, that uses this underlying client?


Solution

    1. IOReactorConfig represents the I/O reactor level configuration parameters applicable to the I/O selector and I/O channels created and managed by the reactor. This is the lowest level of configuration parameters. These configuration parameters are specific to the async (event-driven) I/O transport. SocketConfig is the classic (blocking) I/O transport equivalent. These parameters apply prior to the connection setup or TLS handshake

    2. ConnectionConfig represents the connection management level configuration parameters applicable to individual HTTP connections and NOT specific to an I/O transport model. They work the same way with the classic and the async transports. These parameters apply to connections during their entire life time. There is a certain overlap with the I/O transport model specific parameters, for instance the socket timeout, can optionally override that defined at the I/O channel level.

    3. TlsConfig represents TLS handshake specific configuration parameters applicable to individual connections during the TLS handshake in some cases before the connection setup is fully complete. There is a certain overlap with the I/O transport model specific parameters, for instance the socket timeout, can optionally override that defined at the I/O channel level for the duration of the TLS handshake. This is also the configuration level that defines the HTTP protocol negotiation policy.

    4. Http1Config represents the HTTP/1.1 protocols specific configuration parameters applicable to HTTP/1.1 and HTTP/1.0 connections. These parameters apply post the connection setup and prior to individual message exchanages.

    5. H2Config represents the HTTP/2 protocols specific configuration parameters applicable to HTTP/2 connections. These parameters apply post the connection setup and prior to individual message exchanges.

    6. RequestConfig represents the request level configuration parameters applicable to individual HTTP message exchanges and NOT specific to an I/O transport model. This is the topmost level of configuration parameters. These parameters apply in the course of the request / response message exchange post the connection setup (that includes the complete route negotiation, TLS handshake, proxy tunnel setup, etc). There is a certain overlap with the connection management level parameters, for instance the response timeout, can optionally override the socket defined at the connection level.

    For completeness there are also CharCodingConfig that apply to text based connections and CacheConfig that apply to HTTP caches.