PreferredWithFallbackRoutingStrategy
Overview
The PreferredWithFallbackRoutingStrategy
attempts to use a designated preferred gateway first, and only falls back to an alternative routing strategy if the preferred gateway fails or is unavailable. This strategy is ideal for applications with dedicated infrastructure or specific gateway requirements.
How It Works
- Health Check: Performs a HEAD request to the preferred gateway with a 1000ms timeout
- Success: If the preferred gateway responds with a successful status, it's used
- Failure: If the preferred gateway fails or times out, the fallback strategy is used
- Logging: All attempts and failures are logged for monitoring
Basic Usage
import {
PreferredWithFallbackRoutingStrategy,
FastestPingRoutingStrategy,
} from '@ar.io/wayfinder-core'
const strategy = new PreferredWithFallbackRoutingStrategy({
preferredGateway: 'https://my-gateway.com',
fallbackStrategy: new FastestPingRoutingStrategy({ timeoutMs: 500 }),
})
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
preferredGateway | string | required | URL of the preferred gateway |
fallbackStrategy | RoutingStrategy | FastestPingRoutingStrategy() | Strategy to use when preferred gateway fails |
logger | Logger | defaultLogger | Optional logger instance |
Related
- FastestPingRoutingStrategy: Network-based gateway discovery
- RoundRobinRoutingStrategy: Even distribution across gateways
- RandomRoutingStrategy: Randomized gateway selection
- StaticRoutingStrategy: Always use a single, fixed gateway