Setup Environment for Circuit Breakers
Before building circuit breaker patterns, you'll set up a test environment with mock downstream systems that can fail on demand, allowing you to observe circuit breaker behavior.
Prerequisites
This example requires the following services to be running:
Before you begin, please ensure these services are set up and running according to their respective guides. Additionally, ensure you have completed the Local Development Setup guide for general environment configuration.
Step 1: Configure Example-Specific Variables
After setting up the core services, configure circuit breaker-specific variables:
# Circuit breaker configuration
export CIRCUIT_BREAKER_TIMEOUT="5s"
export CIRCUIT_BREAKER_RETRIES="3"
export CIRCUIT_BREAKER_RETRY_PERIOD="2s"
# Mock API configuration
export MOCK_API_URL="http://localhost:8081"
export API_TOKEN="test-token"
# Verify configuration
echo "Circuit breaker timeout: $CIRCUIT_BREAKER_TIMEOUT"
echo "Mock API URL: $MOCK_API_URL"
Step 2: Start Mock Downstream Services
Create mock services that can simulate failures for testing circuit breakers.
Mock HTTP API Server
Start the mock API server from the scripts directory:
# Start the mock API server in the background
scripts/mock-api-server.py &
MOCK_API_PID=$!
echo "Mock API started with PID: $MOCK_API_PID"
Next: Step 1: HTTP Circuit Breakers - Implement circuit breaker protection for HTTP APIs