Circuit Breaker Panel with lagom
source link: https://blog.knoldus.com/circuitbreakerpanel-with-lagom/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Circuit Breaker Panel with lagom
Reading Time: 2 minutes
Up to v1.3.x, you could use circuit breaker pattern with lagom only in service descriptor usually. To apply circuit breaker to some arbitrary API you had to generally use the underlying akka circuit breaker . How to use circuit breaker with unmanaged services is explained pretty well at https://blog.knoldus.com/2017/06/15/lagom-circuit-breaker-what-why-and-how/ and if you want to poke around with the underlying akka circuit breaker you can take a look at https://doc.akka.io/docs/akka/2.5/common/circuitbreaker.html.
To use a circuitbreaker with some arbitrary API ( for e.g. a database API like couchbase) with lagom 1.4.x you can use CircuitBreakerPanel. The sole method in this class allows you to write code like –
xxxxxxxxxx
circuitbreaker.withCircuitBreaker("circuit-breaker-name", CompletableFuture.supplyAsync(() -> yourCode);
With correct configuration defined for “circuit-breaker-name”, you can leverage the circuit breaker pattern easily with arbitrary API calls. If your CompletionStage throws any error then it counts towards your CircuitBreaker going to an open state.
Now, you might not want your CircuitBreaker to go into an open state for certain type of exceptions ( say there is some sort of validation going inside your CompletionStage). For this, you can whitelist certain exceptions using the field “lagom.circuit-breaker.circuit-breaker-name.exception-whitelist” as shown below –
lagom.circuit-breaker { breakerA { max-failures = 3 reset-timeout = 20s exception-whitelist = ["java.lang.NullPointerException"] } }
It accepts an array of strings in which you can define all the exceptions for which you don’t want the circuit breaker to go towards an open state. I have created a minimal example to showcase how to leverage CircuitBreakerPanel along with exception whitelisting at –
Recommend
-
60
There is no denying that in the last few years, technologies like Docker and Kubernetes, to name a few of the most relevant, have revolutionized how we reason about software development and deployment. But whilst...
-
19
In a previous post we talked about the implementation of the Circuit Breaker pattern . As a reminder, the Circuit Breaker is a pattern that...
-
36
Circuit Breaker PHP is a package by Leonardo Carmo which implements the Circuit breaker design pattern...
-
29
An ability to handle communication failures in an inter-service communication is an absolute necessity for every single service mesh framework. It includes handling of timeouts and HTTP error codes. In this article I’m going to show how to confi...
-
14
Circuit breaker and retries on Kubernetes with Istio and Spring Boot An ability to handle communication failures in an inter-service communication is an absolute necessity for every single service mesh framework. It includes...
-
14
Engineering at Teachers Pay Teachers
-
11
In this series so far, we have learned about Resilience4j and its Retry, RateLimiter,
-
13
Node.js Resiliency Concepts: The Circuit Breaker Andrei Gaspar on Jul 22, 2020 “I absolutely love AppSignal.” Discover AppSignal
-
7
Victoria has been plunged into lockdown following further diagnoses of the highly contagious UK strain of COVID-19. Premier Daniel Andrews has said the state-wide lockdown is necessary to get on top of transmissions and ensure Victor...
-
6
Fail fast with Opossum circuit breaker in Node.js
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK