Skip to main content

Creating CircuitBreaker adapters

Implementing your custom ICircuitBreakerAdapter​

In order to create an adapter you need to implement the ICircuitBreakerAdapter contract.

Implementing your custom ICircuitBreakerStorageAdapter​

We provide an additional contract ICircuitBreakerStorageAdapter for building custom circuit-breaker storage adapters tailored to DatabaseCircuitBreakerAdapter and DatabaseCircuitBreakerProviderFactory.

Testing your custom ICircuitBreakerStorageAdapter​

We provide a complete test suite to test your circuit-breaker storage adapter implementation. Simply use the circuitBreakerStorageTestSuite function:

  • Preconfigured Vitest test cases
  • Common edge case coverage

Usage example:

./samples/circuit-breaker-storage-test-suite.ts
import { beforeEach, describe, expect, test } from "vitest";
import { circuitBreakerStorageAdapterTestSuite } from "eridu-tech/circuit-breaker/test-utilities";
import { MemoryCircuitBreakerStorageAdapter } from "eridu-tech/circuit-breaker/memory-circuit-breaker-storage-adapter";

describe("class: MyCircuitBreakerStorageAdapter", () => {
circuitBreakerStorageAdapterTestSuite({
createAdapter: () => new MemoryCircuitBreakerStorageAdapter(),
test,
beforeEach,
expect,
describe,
});
});

Implementing your custom ICircuitBreakerProvider class​

In some cases, you may need to implement a custom CircuitBreakerProvider class to optimize performance for your specific technology stack. You can then directly implement the ICircuitBreakerProvider contract.

Further information​

For further information refer to eridu-tech/circuit-breaker API docs.