Skip to content

Commit

Permalink
add http reuse strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
JNSimba committed Jun 24, 2024
1 parent 9fe85ca commit f254b3a
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,37 @@

package org.apache.doris.flink.sink;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.NoConnectionReuseStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;

import java.util.concurrent.TimeUnit;

/**
* util to build http client.
*/
public class HttpUtil {
private RequestConfig requestConfigStream =
RequestConfig.custom()
.setConnectTimeout(60 * 1000)
.setConnectionRequestTimeout(60 * 1000)
.build();

private final HttpClientBuilder httpClientBuilder = HttpClients
.custom()
.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
protected boolean isRedirectable(String method) {
return true;
}
});
})
.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
.evictExpiredConnections()
.evictIdleConnections(60, TimeUnit.SECONDS)
.setDefaultRequestConfig(requestConfigStream);

public CloseableHttpClient getHttpClient() {
return httpClientBuilder.build();
Expand Down

0 comments on commit f254b3a

Please sign in to comment.