Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max allowed retries in reactive retry policy #607

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions feign-reactor-bom/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
4 changes: 1 addition & 3 deletions feign-reactor-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ abstract public class RetryPublisherHttpClient implements PublisherHttpClient {
protected final String feignMethodKey;
protected final PublisherHttpClient publisherClient;
private final Retry retry;
private final ReactiveRetryPolicy retryPolicy;

private final ExceptionPropagationPolicy exceptionPropagationPolicy;

Expand All @@ -52,6 +53,7 @@ protected RetryPublisherHttpClient(
this.feignMethodKey = methodMetadata.configKey();
this.retry = wrapWithRetryLog(retryPolicy.retry(), feignMethodKey);
this.exceptionPropagationPolicy = retryPolicy.exceptionPropagationPolicy();
this.retryPolicy = retryPolicy;
}

protected Retry getRetry(ReactiveHttpRequest request){
Expand All @@ -64,7 +66,7 @@ private Retry wrapWithOutOfRetriesLog(ReactiveHttpRequest request) {
public Publisher<?> generateCompanion(Flux<RetrySignal> retrySignals) {
return Flux.<Object>from(retry.generateCompanion(retrySignals))
.onErrorResume(throwable -> Mono.just(new OutOfRetriesWrapper(throwable, request)))
.zipWith(Flux.range(1, Integer.MAX_VALUE), (object, index) -> {
.zipWith(Flux.range(1, retryPolicy.maxAllowedRetries()), (object, index) -> {
if(object instanceof OutOfRetriesWrapper){
OutOfRetriesWrapper wrapper = (OutOfRetriesWrapper) object;
if(index == 1){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public long retryDelay(Throwable error, int attemptNo) {
}
}

@Override
public int maxAllowedRetries() {
return maxRetries;
}

public static class Builder implements ReactiveRetryPolicy.Builder{
private int maxRetries;
private long backoffInMs = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public Retry retry() {
return filter(retryPolicy.retry(), toRetryOn);
}

@Override
public int maxAllowedRetries() {
return retryPolicy.maxAllowedRetries();
}

static Retry filter(
Retry retry,
Predicate<Throwable> toRetryOn){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface ReactiveRetryPolicy {

Retry retry();

int maxAllowedRetries();

interface Builder {
ReactiveRetryPolicy build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ExceptionPropagationPolicy exceptionPropagationPolicy(){
@Override
public Retry retry() {
return Retry.from(errors -> errors
.zipWith(Flux.range(1, Integer.MAX_VALUE), (signal, index) -> {
.zipWith(Flux.range(1, maxAllowedRetries()), (signal, index) -> {
long delay = retryDelay(signal.failure(), index);
if (delay >= 0) {
return Tuples.of(delay, signal);
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 1 addition & 3 deletions feign-reactor-spring-cloud-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
4 changes: 2 additions & 2 deletions feign-reactor-test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-parent</artifactId>
<relativePath>../feign-reactor-parent</relativePath>
<version>4.0.2</version>
<version>4.0.2</version
</parent>

<artifactId>feign-reactor-test</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
Loading