Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Circuit Breaker

Gustavo Denis edited this page Oct 31, 2019 · 1 revision

#Circuit Breaker Circuit Breaker is used when a system is seriously struggling. In a distributed environment, calls to remote resources and services can fail due to transient faults, such as slow network connections and timeouts, or if resources are responding slowly or are temporarily unavailable. These faults typically correct themselves after a short time, and a robust cloud application should be prepared to handle them. Therefore, its necessary some kind of defense barrier so that excessive requests stop when it is not worth keeping trying. That defense barrier is precisely the circuit breaker.

##Polly As when implementing retries, the recommended approach for circuit breakers is to take advantage of proven .NET libraries like Polly. Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Circuit Breaker.

Add Polly (bot) to your team.(https://github.com/App-vNext/Polly)

To use the Polly framework, add the code above on the Startup class

app.UsePolly();

Case the startup command is not added, Liquid will initialize the Workbench without Polly features.

##LightApi.cs Add Polly policy in the appsettings.json of the microservice in use

"Retry" means the number of times to retry connect with the microservice "Wait" means the seconds to wait before retry again. "IsBackOff" defines where the delays between attempts increase with the number of failures.

 "LightAPI": {
    "Basket": {
      "Host": "http://localhost",
      "Port": "59034",
      "Suffix": "api/v1",
      "Telemetry": true,
      "Polly": {
        "Retry": 10,
        "IsBackOff": true,
        "Wait": 0
      }
    }
  }, 

To use the Polly framework from Liquid use Liquid.Microservices.Runtime namespace.

Clone this wiki locally