commercetools / commercetools-sdk-java-v2

The e-commerce SDK from commercetools for Java.
https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/index.html
Apache License 2.0
34 stars 15 forks source link

Default Read and Request timeout with Apache Client #404

Closed pintomau closed 1 year ago

pintomau commented 1 year ago

Hi.

In other clients I do see some explicit 120 seconds to connect, read, write timeout.

Wondering if for the Apache client we're defaulting to org.apache.hc.client5.http.config.RequestConfig#DEFAULT or something else?

And what would be CT's recommended way to set default request configuration timeouts?

Say, something like this?

return new CtApacheHttpClient(
        httpAsyncClientBuilder ->
            httpAsyncClientBuilder
                .setDefaultRequestConfig(RequestConfig.custom()
                    .setConnectionRequestTimeout(10, TimeUnit.SECONDS)
                    .setConnectTimeout(10, TimeUnit.SECONDS)
                    .setResponseTimeout(10, TimeUnit.SECONDS)
                    .build())
    );

Or would the Queuing middleware be the way to go as explained in https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/com/commercetools/docs/meta/ClientTuning.html ?

Thanks.

jenschude commented 1 year ago

The Apache Client module creates a client instance with it's default parameters. I took a look and it seems it's 3 minutes for response and connect timeouts.

To manually configure them you can directly instanciate the Client instance and configure it according to the Apache HTTP client docs:

        ApiRootBuilder.of(new CtApacheHttpClient(
                64,
                64,
                builder -> builder
                        .setIOReactorConfig(IOReactorConfig.custom() // e.g. set the socket timeout
                                .setSoTimeout(10, TimeUnit.SECONDS)
                                .build())
                        .setDefaultRequestConfig(RequestConfig.custom() // or configure the request parameters
                                .setResponseTimeout(10, TimeUnit.SECONDS)
                                .setConnectTimeout(3, TimeUnit.SECONDS)
                                .build())
        ));

Btw we decided to set some values in the other clients to avoid having connections and responses without any timeout set.

pintomau commented 1 year ago

Thanks for the confirmation, Jens.