Crius
Crius is a simple hystrix-like circuit breaker for rust.
"In the midst of chaos, there is also opportunity"
Usage
Simple command
extern crate crius;
use Command;
Command with fallback
extern crate crius;
use Command;
use Error;
use fmt;
//Define Error Type
;
unsafe
unsafe
Command with custom configuration
extern crate crius;
use Command;
use Config;
Error types and handling
The error types that are provided by trychis can be found in crius::command::error
.
Currently it only contains one error RejectError
, which is returned when the circuit is open and therefore the command rejected.
If an error is occurring it will be returned in the receiver, except when a fallback is provided where it is than passed as a param to the fallback function.
The returned / passed error is of type Error + Send + Sync + 'static
- with this we can check and downcast to the original error, for example:
Configuration
circuit_open_ms
- Time in ms commands are rejected after the circuit opened - Default 5000
error_threshold
- Minimum amount of errors for the circuit to break - Default 10
error_threshold_percentage
- Minimum error percentage for the circuit to break - Default 50
buckets_in_window
- Trychis is using a rolling window to track success/error calls, this property defines the amount of buckets in a window (buckets_in_window * bucket_size_in_ms is the overall length in ms of the window) - Default 10
bucket_size_in_ms
- This property defines the ms a bucket is long, i.e. each x ms a new bucket will be created (buckets_in_window * bucket_size_in_ms is the overall length in ms of the window) - Default 1000