https://github.com/making/retryable-client-http-request-interceptor
RetryableClientHttpRequestInterceptor for RestTemplate and RestClient
https://github.com/making/retryable-client-http-request-interceptor
Last synced: 6 months ago
JSON representation
RetryableClientHttpRequestInterceptor for RestTemplate and RestClient
- Host: GitHub
- URL: https://github.com/making/retryable-client-http-request-interceptor
- Owner: making
- License: apache-2.0
- Created: 2023-04-28T01:11:50.000Z (almost 3 years ago)
- Default Branch: develop
- Last Pushed: 2025-05-23T00:36:29.000Z (11 months ago)
- Last Synced: 2025-05-30T12:49:09.019Z (11 months ago)
- Language: Java
- Homepage:
- Size: 174 KB
- Stars: 16
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# retryable-client-http-request-interceptor
RetryableClientHttpRequestInterceptor for `RestTemplate` and `RestClient`
For Spring 6+ / Spring Boot 3+
```xml
am.ik.spring
retryable-client-http-request-interceptor
0.7.0
```
For Spring 5 / Spring Boot 2
```xml
am.ik.spring
retryable-client-http-request-interceptor-spring5
0.7.0
```
### How to use
```java
private final RestTemplate restTemplate;
public MyClient(RestTemplateBuilder builder){
this.restTemplate = builder
.rootUri("http://example.com")
.additionalInterceptors(new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2)))
.build();
}
```
or
```java
// Spring 6.1+ / Spring Boot 3.2+
private final RestClient restClient;
public MyClient(RestClient.Builder builder){
this.restClient = builder
.baseUrl("http://example.com")
.requestInterceptor(new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2)))
.build();
}
```
* How to use exponential backoff
```java
new RetryableClientHttpRequestInterceptor(new ExponentialBackOff(100, 2))
```
* How to configure `retryableResponseStatuses` (default: 408, 425, 429, 500, 503, 504)
```java
new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2), Set.of(500, 503))
```
* How to configure whether to `retryClientTimeout` (default: true)
```java
new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2),
options -> options.removeRetryableIOException(RetryableIOExceptionPredicate.CLIENT_TIMEOUT))
```
* How to configure whether to `retryConnectException` (default: true)
```java
new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2),
options -> options.removeRetryableIOException(RetryableIOExceptionPredicate.CONNECT_TIMEOUT))
```
* How to configure whether to `retryUnknownHostException` (default: true)
```java
new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2),
options -> options.removeRetryableIOException(RetryableIOExceptionPredicate.UNKNOWN_HOST))
```
* How to enable client-side load balancing during retries (Since 0.3.0)
```java
LoadBalanceStrategy loadBalanceStrategy = /* Bing your own strategy */;
new RetryableClientHttpRequestInterceptor(new FixedBackOff(100, 2),
options -> options.loadBalanceStrategy(loadBalanceStrategy));
```
### License
Licensed under the Apache License, Version 2.0.