Giter VIP home page Giter VIP logo

microprofile-fault-tolerance's Introduction

microprofile fault tolerance

Eclipse MicroProfile Fault Tolerance

Introduction

It is increasingly important to build fault tolerant micro services. Fault tolerance is about leveraging different strategies to guide the execution and result of some logic. Retry policies, bulkheads, and circuit breakers are popular concepts in this area. They dictate whether and when executions should take place, and fallbacks offer an alternative result when an execution does not complete successfully.

Overview

Fault Tolerance provides developers with the following strategies for dealing with failure:

  • Timeout: Define a maximum duration for execution

  • Retry: Attempt execution again if it fails

  • Bulkhead: Limit concurrent execution so that failures in that area can’t overload the whole system

  • CircuitBreaker: Automatically fail fast when execution repeatedly fails

  • Fallback: Provide an alternative solution when execution fails

Fault Tolerance provides an annotation for each strategy which can be placed on the methods of CDI beans. When an annotated method is called, the call is intercepted and the corresponding fault tolerance strategies are applied to the execution of that method.

Documentation

For links to the latest maven artifacts, Javadoc and specification document, see the latest release.

Example

Apply the retry and fallback strategies to doWork(). It will be executed up to two additional times if if throws an exception. If all executions throw an exception, doWorkFallback() will be called and the result of that returned instead.

@ApplicationScoped
public class FaultToleranceBean {

   @Retry(maxRetries = 2)
   @Fallback(fallbackMethod = "doWorkFallback")
   public Result doWork() {
      return callServiceA(); // This service usually works but sometimes
                             // throws a RuntimeException
   }

   private Result doWorkFallback() {
      return Result.emptyResult();
   }
}

From elsewhere, inject the FaultToleranceBean and call the method:

@ApplicationScoped
public class TestBean {

    @Inject private FaultToleranceBean faultToleranceBean;

    public void test() {
        Result theResult = faultToleranceBean.doWork();
    }
}

Configuration

The annotation parameters can be configured via MicroProfile Config. For example, imagine you have the following code in your application:

package org.microprofile.readme;

@ApplicationScoped
public class FaultToleranceBean {

   @Retry(maxRetries = 2)
   public Result doWork() {
      return callServiceA(); // This service usually works but sometimes
                             // throws a RuntimeException
   }
}

At runtime, you can configure maxRetries to be 6 instead of 2 for this method by defining the config property org.microprofile.readme.FaultToleranceBean/doWork/Retry/maxRetries=6.

Alternatively, you can configure maxRetries to be 6 for all instances of Retry in your application by specifying the property Retry/maxRetries=6.

Contributing

Do you want to contribute to this project? Find out how you can help here.

microprofile-fault-tolerance's People

Contributors

emily-jiang avatar azquelt avatar eclipse-microprofile-bot avatar carlosdlr avatar neilgsyoung avatar hutchig avatar ladicek avatar ondromih avatar antoinesd avatar jcass149 avatar brunobat avatar doychin avatar kenfinnigan avatar mcfoggy avatar johnament avatar phillip-kruger avatar benjamin-confino avatar pandrex247 avatar jbee avatar tevans78 avatar kwsutter avatar mkouba avatar manovotn avatar jgauravgupta avatar xstefank avatar jgallimore avatar michalszynkiewicz avatar rhusar avatar sdaschner avatar tomashofman avatar

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.