Skip to content

Commit

Permalink
feat: add retry
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Aug 18, 2024
1 parent 4193874 commit 80738b0
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.Optional;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
Expand All @@ -28,10 +30,12 @@
@Component
public class ConnectorClient {
private RestClient restClient;

public ConnectorClient() {
var requestConfig = RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(10000)).build();
var httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
var httpClient = HttpClientBuilder.create()
.setRetryStrategy(new DefaultHttpRequestRetryStrategy(1, TimeValue.ofSeconds(1)))
.setDefaultRequestConfig(requestConfig).build();
var factory = new HttpComponentsClientHttpRequestFactory(httpClient);
factory.setConnectTimeout(5000);
factory.setConnectionRequestTimeout(5000);
Expand All @@ -56,7 +60,6 @@ public <T> Optional<T> restCall(String url, MultiValueMap<String, String> header
}

private ResponseSpec createCall(String url, MultiValueMap<String, String> headerValues) {
return this.restClient.get().uri(url)
.headers(headers -> headers.addAll(headerValues)).retrieve();
return this.restClient.get().uri(url).headers(headers -> headers.addAll(headerValues)).retrieve();
}
}

0 comments on commit 80738b0

Please sign in to comment.