https://github.com/vaslabs/talos
Lawful circuit breakers for Scala. Akka and monix circuit breaker implementations with monitoring.
https://github.com/vaslabs/talos
akka akka-circuit-breaker bulkhead circuit-breaker circuitbreaker gateway kamon monitoring monix monix-circuit-breaker scala
Last synced: about 1 month ago
JSON representation
Lawful circuit breakers for Scala. Akka and monix circuit breaker implementations with monitoring.
- Host: GitHub
- URL: https://github.com/vaslabs/talos
- Owner: vaslabs
- License: mit
- Created: 2018-10-19T12:40:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-13T15:37:30.000Z (over 3 years ago)
- Last Synced: 2025-03-18T11:48:29.280Z (about 2 months ago)
- Topics: akka, akka-circuit-breaker, bulkhead, circuit-breaker, circuitbreaker, gateway, kamon, monitoring, monix, monix-circuit-breaker, scala
- Language: Scala
- Homepage: https://talos.vaslabs.org/index.html
- Size: 31.5 MB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# talos [](https://travis-ci.com/vaslabs/talos) [](https://maven-badges.herokuapp.com/maven-central/org.vaslabs.talos/taloscore_2.12) [](https://app.codacy.com/app/vaslabs/talos?utm_source=github.com&utm_medium=referral&utm_content=vaslabs/talos&utm_campaign=Badge_Grade_Dashboard) [](https://www.codacy.com/app/vaslabs/talos?utm_source=github.com&utm_medium=referral&utm_content=vaslabs/talos&utm_campaign=Badge_Coverage) [](https://hub.docker.com/r/vaslabs/talos-gateway/) [](https://scala-steward.org)
Talos is enforcing some theory from literature concerning circuit breakers in the form of typeclasses and laws.
Read more around the theory [here](https://vaslabs.github.io/talos/laws/index.html)
The main deliverable of Talos is fine grained monitoring.
## Usage
Talos is modularised. You can twist it and pick the dependencies that fit your need. But let's go step by step.```scala
libraryDependencies += "org.vaslabs.talos" %% "taloscore" % "2.1.0"
libraryDependencies += "org.vaslabs.talos" %% "talosakkasupport" % "2.1.0"
libraryDependencies += "org.vaslabs.talos" %% "taloskamon" % "2.1.0"
```
The events library provides a way to stream events on what's happening in the circuit breakers. E.g. combining with the talosakkasupport you can do:
```scala
import akka.actor.typed.{ActorSystem, ActorRef}
import akka.actor.typed.scaladsl.adapter._
import akka.pattern.CircuitBreaker
import cats.effect.IO
import talos.circuitbreakers.TalosCircuitBreaker
import talos.circuitbreakers.akka._import scala.concurrent.duration._
def createCircuitBreaker(name: String = "testCircuitBreaker")
(implicit system: ActorSystem[_]): AkkaCircuitBreaker.Instance = {
AkkaCircuitBreaker(
name,
CircuitBreaker(
system.scheduler.toClassic,
5,
2 seconds,
5 seconds
)
)
}```
If you have an existing solution based on Akka circuit breaker and you can extract the circuit breaker like this.
```scala
val akkaCB: CircuitBreaker = talosCircuitBreaker.circuitBreaker.unsafeRunSync()
```Otherwise you can use the TalosCircuitBreaker typeclass directly
```scala
val action: IO[Unit] = talosCircuitBreaker.protect(IO(println("Running inside the circuit breaker")))
action.unsafeRunSync()
```Talos also supports the CircuitBreaker from [monix](https://vaslabs.github.io/talos/monix/monix.html)
### Complete usage example
How to code can be found here:
https://github.com/vaslabs/talos/blob/master/examples/src/main/scala/talos/examples/ExampleApp.scala### Laws
If you wish to implement your own TalosCircuitBreaker typeclasses you can test them against the laws library:
```scala
libraryDependencies += "org.vaslabs.talos" %% "taloslaws" % "2.1.0" % Test
```## Run the demo
- Spin up the docker images provided:
```bash
cd examples
docker-compose up
```You can see the kamon status [here](http://localhost:5266) and the prometheus metrics are exposed
[here](http://localhost:9095) .### How Tos
1. Setup docker to work with Kamon: Look at build.sbt, find dockerCommonSettings
2. Setup logging: Look in the example module in the resources for the logback.xml file.## Architecture

Note: The hystrix reporter is no longer supported (last supported version 1.0.0)