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

custom order of fault tolerance strategies in programmatic API #594

Open
Ladicek opened this issue Mar 8, 2022 · 3 comments
Open

custom order of fault tolerance strategies in programmatic API #594

Ladicek opened this issue Mar 8, 2022 · 3 comments

Comments

@Ladicek
Copy link
Contributor

Ladicek commented Mar 8, 2022

The MicroProfile Fault Tolerance specification prescribes order in which fault tolerance strategies must apply. That's fine (and there's no other way) for the declarative API, but the programmatic API should offer a way to customize the order. In such case, certain fault tolerance strategies can even apply multiple times (fallback most importantly, because in the middle of the fault tolerance strategies chain, there's no other way how to handle exceptions). I'm thinking something like FaultTolerance.create().customOrder()...:

  • customOrder() must be called before any fault tolerance strategy is added
  • if called, order of adding strategies to the builder becomes meaningful -- it is the order in which the strategies will be applied
@Ladicek Ladicek added this to the 5.4.0 milestone Mar 8, 2022
@Ladicek Ladicek removed this from the 5.4.0 milestone Mar 29, 2022
@magicprinc
Copy link
Contributor

Your current order is quite standard in industry.
The Resilience4j Aspects order is the following:
Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( Function ) ) ) ) )

Could I propose a simpler enhancement first:
allow user to add additional Fault Tolerance Strategy at the beginning and
at the end of chain (direct around Callable/before Bulkhead and after Fallback / before returning result to user)

@Ladicek
Copy link
Contributor Author

Ladicek commented Nov 20, 2023

I certainly don't intend to make FaultToleranceStrategy a public API. But specifically for adding something at the beginning or at the end, that should already be pretty simple, you just wrap the Callables yourself.

@magicprinc
Copy link
Contributor

for adding something at the beginning or at the end, that should already be pretty simple, you just wrap the Callables yourself.

This is an obvious solution, no surprise :-)
But Callable doesn't have InvocationContext.
In the absence of which, you have to build your own session context infrastructure.

Here is a draft of a simple idea, how to improve the situation
#924

BTW One of thing I miss from failsafe is
https://failsafe.dev/execution-context/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants