Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CircuitBreaker

An implementation of the circuit breaker pattern for Vert.x

Hierarchy

  • CircuitBreaker

Index

Methods

close

  • Closes the circuit breaker. It stops sending events on its state on the event bus. This method is not related to the close state of the circuit breaker. To set the circuit breaker in the close state, use {@link CircuitBreaker#reset}.

    Returns CircuitBreaker

closeHandler

  • closeHandler(handler: ((res: void) => void) | Handler<void>): CircuitBreaker
  • Sets a invoked when the circuit breaker state switches to close.

    Parameters

    • handler: ((res: void) => void) | Handler<void>

    Returns CircuitBreaker

execute

  • execute<T>(command: ((res: Promise<T>) => void) | Handler<Promise<T>>): PromiseLike<T>
  • execute<T>(command: ((res: Promise<T>) => void) | Handler<Promise<T>>, handler: ((res: AsyncResult<T>) => void) | Handler<AsyncResult<T>>): void
  • Same as {@link CircuitBreaker#executeWithFallback} but using the circuit breaker default fallback.

    Type parameters

    • T

    Parameters

    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>

    Returns PromiseLike<T>

  • Same as {@link CircuitBreaker#executeWithFallback} but using the circuit breaker default fallback.

    Type parameters

    • T

    Parameters

    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>
    • handler: ((res: AsyncResult<T>) => void) | Handler<AsyncResult<T>>

    Returns void

executeAndReport

  • executeAndReport<T>(resultPromise: Promise<T>, command: ((res: Promise<T>) => void) | Handler<Promise<T>>): CircuitBreaker
  • Same as {@link CircuitBreaker#executeAndReportWithFallback} but using the circuit breaker default fallback.

    Type parameters

    • T

    Parameters

    • resultPromise: Promise<T>
    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>

    Returns CircuitBreaker

executeAndReportWithFallback

  • executeAndReportWithFallback<T>(resultPromise: Promise<T>, command: ((res: Promise<T>) => void) | Handler<Promise<T>>, fallback: (arg: Throwable) => T): CircuitBreaker
  • Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of failure.

    The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.

    Unlike {@link CircuitBreaker#executeWithFallback}, this method does return a object, but let the caller pass a object on which the result is reported. If the fallback is called, the future is successfully completed with the value returned by the fallback function. If the fallback throws an exception, the future is marked as failed.

    Type parameters

    • T

    Parameters

    • resultPromise: Promise<T>
    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>
    • fallback: (arg: Throwable) => T
        • (arg: Throwable): T
        • Parameters

          • arg: Throwable

          Returns T

    Returns CircuitBreaker

executeWithFallback

  • executeWithFallback<T>(command: ((res: Promise<T>) => void) | Handler<Promise<T>>, fallback: (arg: Throwable) => T): PromiseLike<T>
  • executeWithFallback<T>(command: ((res: Promise<T>) => void) | Handler<Promise<T>>, fallback: (arg: Throwable) => T, handler: ((res: AsyncResult<T>) => void) | Handler<AsyncResult<T>>): void
  • Same as {@link CircuitBreaker#executeWithFallback} but using a callback.

    Type parameters

    • T

    Parameters

    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>
    • fallback: (arg: Throwable) => T
        • (arg: Throwable): T
        • Parameters

          • arg: Throwable

          Returns T

    Returns PromiseLike<T>

  • Same as {@link CircuitBreaker#executeWithFallback} but using a callback.

    Type parameters

    • T

    Parameters

    • command: ((res: Promise<T>) => void) | Handler<Promise<T>>
    • fallback: (arg: Throwable) => T
        • (arg: Throwable): T
        • Parameters

          • arg: Throwable

          Returns T

    • handler: ((res: AsyncResult<T>) => void) | Handler<AsyncResult<T>>

    Returns void

failureCount

  • failureCount(): number
  • Returns number

fallback

  • Sets a default invoked when the bridge is open to handle the "request", or on failure if CircuitBreakerOptions is enabled.

    The function gets the exception as parameter and returns the fallback result.

    Type parameters

    • T

    Parameters

    • handler: (arg: Throwable) => T
        • (arg: Throwable): T
        • Parameters

          • arg: Throwable

          Returns T

    Returns CircuitBreaker

halfOpenHandler

  • halfOpenHandler(handler: ((res: void) => void) | Handler<void>): CircuitBreaker
  • Sets a invoked when the circuit breaker state switches to half-open.

    Parameters

    • handler: ((res: void) => void) | Handler<void>

    Returns CircuitBreaker

name

  • name(): string
  • Returns string

open

  • Explicitly opens the circuit.

    Returns CircuitBreaker

openHandler

  • openHandler(handler: ((res: void) => void) | Handler<void>): CircuitBreaker
  • Sets a invoked when the circuit breaker state switches to open.

    Parameters

    • handler: ((res: void) => void) | Handler<void>

    Returns CircuitBreaker

reset

  • Resets the circuit breaker state (number of failure set to 0 and state set to closed).

    Returns CircuitBreaker

retryPolicy

  • Parameters

    • retryPolicy: (arg: number) => number
        • (arg: number): number
        • Parameters

          • arg: number

          Returns number

    Returns CircuitBreaker

  • Set a RetryPolicy which computes a delay before retry execution.

    Parameters

    Returns CircuitBreaker

state

  • Returns CircuitBreakerState

Static create

  • Creates a new instance of CircuitBreaker.

    Parameters

    Returns CircuitBreaker

  • Creates a new instance of CircuitBreaker, with default options.

    Parameters

    • name: string
    • vertx: Vertx

    Returns CircuitBreaker

Generated using TypeDoc