Comments (4)
There's one way to support a similar use case using existing features in Rest Client and Fault Tolerance. Rest Client has the notion of a ResponseExceptionMapper
, which can be used to map a Response
to an Exception
. For example,
public class MyResponseMapper implements ResponseExceptionMapper<MyException> {
@Override
public MyException toThrowable(Response response) {
if (response.getStatus() != 200) {
System.out.println("Throwing exception");
throw new MyException(response.getStatus());
}
return null;
}
}
In this example, and mainly for simplicity, any status code other than 200 is mapped to an instance of MyException
(naturally, different error codes could be mapped to different exception types). This mapper can be registered as a provider in a client and used with the normal FT @Retry
:
@Path("/greet")
@RegisterRestClient(baseUri="http://localhost:8080")
@RegisterProvider(MyResponseMapper.class)
public interface GreetResourceClient {
@GET
@Retry(retryOn = { MyException.class })
@Produces(MediaType.APPLICATION_JSON)
Response getDefaultMessage();
}
Thus, any time MyException
is thrown, the exception will be caught by the FT handler and the method retried up to 3 times (the default for that annotation).
I understand this may not be as convenient as having a dedicated annotation for this purpose, but it is possible using existing constructs and extensions.
from helidon.
@sammee Have you tried the proposed alternative?
from helidon.
@spericas I have implemented a variant of this. Using ResponseMapper will throw a custom exception for a particular status code. This will be applied for all Rest clients. Instead, I wanted to have retry on some specific api. So i have used @Retry annotation on the method where the api is called and throw a custom exception when the status-code or error is retryable.
Thanks for the suggestion.
from helidon.
I gather from the comments that the workaround or alternative is satisfactory. Closing as won't fix for now.
from helidon.
Related Issues (20)
- MicroProfile Rest Client 3.0.1
- Config - HOCON mapped Map has keys detached with extra parent key
- Support Originating IP discovery in Access Logging HOT 1
- 4.x: add tests for multiple JDK releases
- `OpenTelemetryTracer#spanBuilder` always sets parent to active span; how can developers create a root span (with no parent)?
- 4.x: MP `ConfigSource.getOrdinal()` always returns 100 if default ordinals are used
- 4.x: MP Config does not correctly handling per property overriding with config profiles HOT 1
- Weld uses synchronized in ApplicationScopedContextualInstanceStrategy, so carrier thread is pinned HOT 1
- Add support for Helidon 4 MP client and server
- Document new @ExecuteOn annotation
- [2.x] 4.x: MP `ConfigSource.getOrdinal()` always returns 100 if default ordinals are used
- [3.x] 4.x: MP `ConfigSource.getOrdinal()` always returns 100 if default ordinals are used
- Unable to compile mp-2 with native-image profile
- 4.x - native-image.properties not matching recommended layout
- 4.x - Archetype: include an SLF4J provider when SLF4J is used
- helidon-common sources JAR contains absolute paths
- Forward port of #7024 - Process tags show as span tags in Jaeger viewer with helidon-tracing-jaeger
- Heap pressure and OutOfMemory(OOM) when looking up large number of config keys HOT 8
- Platform pinning observed, potentially, indirectly caused by Helidon MP framework code (JTA) HOT 2
- [4.x] Cannot read config from environment with environment modules variables HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helidon.