PingRoutingStrategy
Overview
The PingRoutingStrategy
is a wrapper strategy that performs a HEAD check on the gateway returned from a provided routing strategy. This ensures that the selected gateway is healthy and responsive before using it for requests, adding an extra layer of reliability to any routing strategy.
How It Works
- Delegate to Inner Strategy: Use the provided routing strategy to select a gateway
- Perform Health Check: Send a HEAD request to the selected gateway
- Validate Response: Check if the gateway responds successfully
- Return Gateway: If healthy, return the selected gateway; if unhealthy, the strategy may retry or fail
Basic Usage
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
routingStrategy | RoutingStrategy | required | The routing strategy to wrap with health checks |
timeoutMs | number | 1000 | Timeout for HEAD requests in milliseconds |
logger | Logger | defaultLogger | Optional logger instance |
Advanced Usage
Combining with Other Strategies
Custom Timeout Configuration
Use Cases
- Production Applications: Add health checks to any routing strategy for increased reliability
- Critical Systems: Ensure gateways are responsive before making important requests
- High Availability: Combine with other strategies to create robust routing systems
- Monitoring: Track gateway health through the ping checks
Related
- FastestPingRoutingStrategy: Network-based gateway discovery
- PreferredWithFallbackRoutingStrategy: Static gateway configuration
- RoundRobinRoutingStrategy: Even distribution across gateways
- RandomRoutingStrategy: Randomized gateway selection
- StaticRoutingStrategy: Always use a single, fixed gateway