Added in: v0.7.6
The Moleculer has a built-in circuit-breaker solution.
What is the circuit breaker?Read more about circuit breaker on Martin Fowler blog.
If you enable it, every service call will be protected by a built-in circuit breaker.
Enable it in the broker options
const broker = new ServiceBroker({ |
Settings
Name | Type | Default | Description |
---|---|---|---|
enabled |
Boolean |
false |
Enable the protection |
maxFailures |
3 |
false |
Breaker trips after 3 failures |
halfOpenTime |
Number |
10000 |
Number of milliseconds to switch from open to half-open state |
failureOnTimeout |
Boolean |
true |
Increment failures if the request is timed out |
failureOnReject |
Boolean |
true |
Increment failures if the request is rejected (by any Error ) |
If the circuit-breaker state is changed, ServiceBroker will send internal & metrics events.