Code Monkey home page Code Monkey logo

Comments (4)

Tembrel avatar Tembrel commented on June 3, 2024 1

Try reversing the order of policies passed to Failsafe.with(...). The "innermost" policy is the last element of the list, and the "outermost" policy is the first element of the list.

I expanded your example into a public gist, where the key line is Collections.reverse(policies).

from failsafe.

Tembrel avatar Tembrel commented on June 3, 2024 1

I'm assuming based on the implied context of your example that what you want is to be able to try a series of endpoints, with some retrying for each one in turn, until one succeeds (or all fail).

If so, I think a more straightforward way to do that is to use a loop over the send action for each endpoint, each one wrapped in a RetryPolicy, as in this gist. In particular, see the runMultiple method. That implementation is obviously not production ready:

  • It only deals with runnables.
  • It treats all exceptions as failures, and the absence of an exception as success.
  • It uses the same RetryPolicy for each runnable.

Each of these points could be addressed fairly easily.

Again, assuming that's what you are ultimately trying to do, there is no need for an elaborate composition of fallbacks and retry policies when a simple loop does the trick.

from failsafe.

mjalvarez avatar mjalvarez commented on June 3, 2024 1

Gotcha. I was thinking along the lines of composition fallback + retry policies. Glad I consulted first.

Again, thank you so much for the answers, and the efforts of illustrating in a simple gist. Have a happy new year! 🍻

from failsafe.

mjalvarez avatar mjalvarez commented on June 3, 2024

Thanks @Tembrel ! I think that did the trick. 😄

Just out of curiosity, is it possible to add retry policy for each fallback?

from failsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.