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

Re-subscription must re-trigger the operation #10810

Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions docs/src/main/asciidoc/rest-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,25 @@ public class CountriesResource {
The previous snippet uses Mutiny reactive types, if you're not familiar with them, read the link:getting-started-reactive#mutiny[Getting Started with Reactive guide] first.
====

When returning a `Uni`, every _subscription_ invokes the remote service.
It means you can re-send the request by re-subscribing on the `Uni`, or use a `retry` as follow:

[source, java]
----

@Inject @RestClient CountriesResource service;

// ...

service.nameAsync("Greece")
.onFailure().retry().atMost(10);

----

If you use a `CompletionStage`, you would need to call the service's method to retry.
This difference comes from the laziness aspect of Mutiny and its subscription protocol.
More details about this can be found in https://smallrye.io/smallrye-mutiny/#_uni_and_multi[the Mutiny documentation].

== Package and run the application

Run the application with: `./mvnw compile quarkus:dev`.
Expand Down
5 changes: 5 additions & 0 deletions extensions/resteasy-mutiny/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package io.quarkus.resteasy.mutiny.runtime;

import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;

import javax.ws.rs.client.CompletionStageRxInvoker;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;

import io.smallrye.mutiny.Uni;

@SuppressWarnings("unchecked")
public class UniRxInvokerImpl implements UniRxInvoker {
private final CompletionStageRxInvoker completionStageRxInvoker;
private final UniProvider UniProvider;
Expand All @@ -18,126 +22,251 @@ public UniRxInvokerImpl(final CompletionStageRxInvoker completionStageRxInvoker)

@Override
public Uni<Response> get() {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.get());
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.get();
}
});
}

@Override
public <T> Uni<T> get(Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.get(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.get(responseType);
}
});
}

@Override
public <T> Uni<T> get(GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.get(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.get(responseType);
}
});
}

@Override
public Uni<Response> put(Entity<?> entity) {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.put(entity));
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.put(entity);
}
});
}

@Override
public <T> Uni<T> put(Entity<?> entity, Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.put(entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.put(entity, responseType);
}
});
}

@Override
public <T> Uni<T> put(Entity<?> entity, GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.put(entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.put(entity, responseType);
}
});
}

@Override
public Uni<Response> post(Entity<?> entity) {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.post(entity));
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.post(entity);
}
});
}

@Override
public <T> Uni<T> post(Entity<?> entity, Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.post(entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.post(entity, responseType);
}
});
}

@Override
public <T> Uni<T> post(Entity<?> entity, GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.post(entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.post(entity, responseType);
}
});
}

@Override
public Uni<Response> delete() {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.delete());
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.delete();
}
});
}

@Override
public <T> Uni<T> delete(Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.delete(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.delete(responseType);
}
});
}

@Override
public <T> Uni<T> delete(GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.delete(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.delete(responseType);
}
});
}

@Override
public Uni<Response> head() {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.head());
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.head();
}
});
}

@Override
public Uni<Response> options() {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.options());
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.options();
}
});
}

@Override
public <T> Uni<T> options(Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.options(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.options(responseType);
}
});
}

@Override
public <T> Uni<T> options(GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.options(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.options(responseType);
}
});
}

@Override
public Uni<Response> trace() {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.trace());
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.trace();
}
});
}

@Override
public <T> Uni<T> trace(Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.trace(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.trace(responseType);
}
});
}

@Override
public <T> Uni<T> trace(GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.trace(responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.trace(responseType);
}
});
}

@Override
public Uni<Response> method(String name) {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name));
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name);
}
});
}

@Override
public <T> Uni<T> method(String name, Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name, responseType);
}
});
}

@Override
public <T> Uni<T> method(String name, GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name, responseType);
}
});
}

@Override
public Uni<Response> method(String name, Entity<?> entity) {
return (Uni<Response>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name, entity));
return (Uni<Response>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name, entity);
}
});
}

@Override
public <T> Uni<T> method(String name, Entity<?> entity, Class<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name, entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name, entity, responseType);
}
});
}

@Override
public <T> Uni<T> method(String name, Entity<?> entity, GenericType<T> responseType) {
return (Uni<T>) UniProvider.fromCompletionStage(completionStageRxInvoker.method(name, entity, responseType));
return (Uni<T>) UniProvider.fromCompletionStage(new Supplier<CompletionStage<?>>() {
@Override
public CompletionStage<?> get() {
return completionStageRxInvoker.method(name, entity, responseType);
}
});
}
}
}
Loading