pub struct HermesClientBuilder { /* private fields */ }Expand description
A builder for creating HermesClient instances with customizable configuration.
The builder provides a convenient way to configure a Hermes client with sensible defaults while allowing customization of all parameters. It follows the builder pattern for a fluent API.
§Default Configuration
- Endpoints: Uses Hermes’s default production endpoints
- Connections: 3 concurrent WebSocket connections
- Timeout: 5 seconds for WebSocket operations
- Backoff: Exponential backoff with default settings
- Channel Capacity: Uses the default 1000
Implementations§
Source§impl HermesClientBuilder
impl HermesClientBuilder
Sourcepub fn with_endpoints(self, endpoints: Vec<Url>) -> Self
pub fn with_endpoints(self, endpoints: Vec<Url>) -> Self
Sets custom WebSocket endpoints for the client.
By default, the client uses Hermes’s production endpoints. Use this method to connect to different environments (staging, local development) or to use custom endpoint configurations.
§Arguments
endpoints- A vector of WebSocket endpoint URLs. Must not be empty.
Sourcepub fn with_num_connections(self, num_connections: usize) -> Self
pub fn with_num_connections(self, num_connections: usize) -> Self
Sets the number of concurrent WebSocket connections to maintain.
More connections provide better redundancy and can improve throughput, but also consume more resources.
§Arguments
num_connections- The number of WebSocket connections (must be > 0)
Sourcepub fn with_backoff(self, backoff: HermesExponentialBackoff) -> Self
pub fn with_backoff(self, backoff: HermesExponentialBackoff) -> Self
Sets the exponential backoff configuration for connection retries.
The backoff strategy determines how the client handles connection failures and retries.
§Arguments
backoff- The exponential backoff configuration
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Sets the timeout duration for WebSocket operations.
This timeout applies to each WebSocket connection, if no response is received within this duration, the connection will be considered failed and retried.
§Arguments
timeout- The timeout duration for each WebSocket
Sourcepub fn with_channel_capacity(self, channel_capacity: usize) -> Self
pub fn with_channel_capacity(self, channel_capacity: usize) -> Self
Sets the capacity of the internal message channel.
This determines how many messages can be buffered internally before the client starts applying backpressure.
§Arguments
channel_capacity- The channel capacity (number of messages)
Sourcepub fn build(self) -> Result<HermesClient>
pub fn build(self) -> Result<HermesClient>
Builds the configured HermesClient instance.
This consumes the builder and creates a new client with the specified
configuration. The client is ready to use but connections are not
established until HermesClient::start is called.
§Returns
Returns Ok(HermesClient) on success, or an error if the configuration
is invalid.
§Errors
Returns an error if:
- No endpoints are configured
- Any configuration parameter is invalid