nestjs-circuit-breaker
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Logo

Nesjs Circuit Breaker

Description

NestJs Circuit Breaker implementation

This project is a simple implementation of Circuit Breaker Pattern to be used as decorator in NestJS services

Installation

tested in node 16.4

$ npm install nestjs-circuit-breaker

Add to the App

export default class MyService {
    @CircuitBreaker({
        fallbackFunction: () => 'fallback return',
    })
    async execute() {
        ...
    }
}

Cache Manager

this application uses the NestJS Cache Manager by default. So your application need to configure this

Parameters in Circuit Breaker

Parameters Description
maxErrorsBeforeOpen Max errors until circuit breaker open and only use the fallback function
errorExpirationTimeInMilliseconds Expiration time that will be used to decrement the count erros, this exists to avoid singular erros to be counted
maxAttemptsInHalfOpenState Max number of parallel tryings in half open state. this doesnt change the flow of circuit breaker, so if have a error in any of the attempts the circuit breaker will be opened again
circuitCheckTimeoutInMilliseconds Timeout until change the cricuit breaker status to HALF_OPEN.
fallbackFunction fallback function used when has an error in the service or when the circuit breaker is opened
logger (Optional) circuit breaker log, by default it uses the NestJS Logger
key unique key used to handle circuit breaker in cache

Package Sidebar

Install

npm i nestjs-circuit-breaker

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

229 kB

Total Files

62

Last publish

Collaborators

  • williamfabre