Example 1
Example 1
import { ResiliencePlugin } from '@setu-ts/resilience-plugin'; import type { IResilienceService } from '@setu-ts/common'; app.register(ResiliencePlugin({ defaultRetry: { limit: 3, delay: 100, backoff: 'exponential' }, })); const resilience = ctx.services.get<IResilienceService>('resilience'); const guarded = resilience.wrap(() => externalApi.call(), { retry: true, timeout: 2000 });
c
BulkheadFullError(message?: string)
Thrown when a bulkhead is at maximum concurrency and its queue is full, so the call is shed (fail-fast load shedding) rather than executed or queued.
c
CircuitOpenError(message?: string)
Thrown when a circuit breaker is open and fails fast without invoking the protected call.
c
TimeoutError(message?: string)
Thrown when a protected call exceeds its per-attempt timeout deadline.
f
ResiliencePlugin(options?: ResiliencePluginOptions): IPlugin
Creates a resilience plugin.
I
ResiliencePluginOptions
Options passed to ResiliencePlugin(). Each default* policy is consumed
when a wrap sets the matching field to true; a wrap requesting true
with no matching default configured throws.
-
defaultBulkhead: BulkheadPolicy
Default bulkhead policy used when a
wrapsetsbulkhead: true. -
defaultCircuitBreaker: CircuitBreakerPolicy
Default circuit-breaker policy used when a
wrapsetscircuitBreaker: true. -
defaultRetry: RetryPolicy
Default retry policy used when a
wrapsetsretry: true.
Usage
import * as Resilience_patterns_plugin__circuit_breaker__retry__timeout__and_bulkhead_composed_around_an_arbitrary________Promise_T___under_the__CAPABILITIES_RESILIENCE_____resilience____capability__ from "resilience-plugin/src/index.ts";