Next Planet of Monkeys

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

    3.1.0 • Public • Published

    Opossum Circuit Breaker Adapter · ci npm (scoped) GitHub license

    Circuit breaker adapter with Opossum.


    Make sure we have the core module @Drizzle-Http/core installed.

    npm i @drizzle-http/core
    npm i @drizzle-http/opossum-circuit-breaker


    Usage typically looks like the example below:

    import { CircuitBreakerCallAdapterFactory } from "@drizzle-http/opossum-circuit-breaker";
    import { DrizzleBuilder } from "@drizzle-http/core";
    import { UndiciCallFactory } from "@drizzle-http/undici";
    import { CircuitBreaker } from "@drizzle-http/opossum-circuit-breaker";
    import { Fallback } from "@drizzle-http/opossum-circuit-breaker";
    import { GET } from "@drizzle-http/core";
    class CustomerApi {
      @CircuitBreaker({ /* Opossum CircuitBreaker.Options */ })
      customers(): Promise<Customer[]> { }
    class CustomerApiFallbacks {
      customersAlt(id: string, error: Error): Promise<Customer> {
        // Fallback implementation
    const factory = new CircuitBreakerCallAdapterFactory({ options: { /* global options */ }, fallbacks: new CustomerApiFallbacks() })
    const api = DrizzleBuilder
      .baseUrl(/* base url */)
      .callFactory(new UndiciCallFactory())


    All functionalities from Opossum are available.
    Some features and extensions:


    Fallback methods follow Opossum specification, same argument list and an error argument at the end.
    There are 3 ways to specify a fallback for a circuit breaker:

    • Specify a fallback class in CircuitBreakerCallAdapterFactory constructor. If a method name matches the one specified in the API class, it will be used as a fallback automatically.
    • Apply the decorator @Fallback() and:
      • If @Fallback() decorator argument is a string, it will try to find the method on the fallback class specified in the CircuitBreakerCallAdapterFactory constructor.
      • If @Fallback decorator receives a function, this function will be the fallback.

    Make sure the fallback methods have right signature: same argument list + error at the end and same return type.


    All circuit breakers associated with a CircuitBreakerCallAdapterFactory are stored in a registry instance. CircuitBreakerCallAdapterFactory accepts a parameter registry. You can pass a custom Registry implementation.

    The circuit breaker instance is only stored in the registry after the first execution. If you want to change the circuit breaker behaviour, prefer to use a LifeCycleListener implementation.


    npm i @drizzle-http/opossum-circuit-breaker

    DownloadsWeekly Downloads






    Unpacked Size

    22.6 kB

    Total Files


    Last publish


    • vitor.salgado