Talos is enforcing some theory from literature concerning circuit breakers in the form of typeclasses and laws.
Read more around the theory here
The main deliverable of Talos is fine grained monitoring.
Talos is modularised. You can twist it and pick the dependencies that fit your need. But let's go step by step.
libraryDependencies += "org.vaslabs.talos" %% "taloscore" % "0.6.0"
libraryDependencies += "org.vaslabs.talos" %% "talosakkasupport" % "0.6.0"
libraryDependencies += "org.vaslabs.talos" %% "taloskamon" % "0.6.0"
libraryDependencies += "org.vaslabs.talos" %% "hystrixreporter" % "0.6.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:
import akka.pattern.CircuitBreaker
import cats.effect.IO
import talos.circuitbreakers.TalosCircuitBreaker
import talos.circuitbreakers.akka.AkkaCircuitBreaker
val talosCircuitBreaker: TalosCircuitBreaker[CircuitBreaker, IO] = AkkaCircuitBreaker(
name,
CircuitBreaker(
actorSystem.scheduler,
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.
val akkaCB: CircuitBreaker = talosCircuitBreaker.circuitBreaker.unsafeRunSync()
Otherwise you can use the TalosCircuitBreaker typeclass directly
val action: IO[Unit] = talosCircuitBreaker.protect(IO(println("Running inside the circuit breaker")))
action.unsafeRunSync()
Talos also supports the CircuitBreaker from monix
Get an akka directive
import akka.http.scaladsl.server.Route
val hystrixReporterDirective: Route = new HystrixReporterDirective().hystrixStreamHttpRoute.run(Clock.systemUTC())
And you can mix the Akka directive with the rest of your application.
The example below shows a complete server start
import java.time.Clock
import akka.actor.ActorSystem
import talos.http._
implicit val TestClock: Clock = Clock.systemUTC()
implicit val actorSystem: ActorSystem = ActorSystem("TalosExample")
val hystrixReporterDirective = new HystrixReporterDirective().hystrixStreamHttpRoute
val server = new StartServer("0.0.0.0", 8080)
val startingServer = server.startHttpServer.run(hystrixReporterDirective)
Now you can consume the hystrix stream from http://localhost:8080/hystrix.stream and point the hystrix dashboard to it.
How to code can be found here: https://github.com/vaslabs/talos/blob/master/examples/src/main/scala/talos/examples/ExampleApp.scala
If you wish to implement your own TalosCircuitBreaker typeclasses you can test them against the laws library:
libraryDependencies += "org.vaslabs.talos" %% "taloslaws" % "0.6.0" % Test
- Spin up the docker images provided:
cd examples
docker-compose up
-
Then go to a browser and navigate to (http://localhost:7979/hystrix-dashboard/) You should see this
-
The address of the stream is http://talos-demo:8080/hystrix.stream
-
Click add stream and then monitor stream.