C - the client type that this builder creates@Experimental public abstract class MultiDbClientBuilder<C> extends AbstractClientBuilder<MultiDbClientBuilder<C>,C>
This builder provides methods specific to multi-db Redis deployments, including multiple weighted endpoints, circuit breaker configuration, health checks, and automatic failover/failback capabilities.
Key Features:
Usage Examples:
MultiDbClient client = MultiDbClient.builder()
.multiDbConfig(
MultiDbConfig.builder()
.database(
DatabaseConfig.builder(
east,
DefaultJedisClientConfig.builder().credentials(credentialsEast).build())
.weight(100.0f)
.build())
.database(DatabaseConfig.builder(
west,
DefaultJedisClientConfig.builder().credentials(credentialsWest).build())
.weight(50.0f).build())
.failureDetector(MultiDbConfig.CircuitBreakerConfig.builder()
.failureRateThreshold(50.0f)
.build())
.commandRetry(MultiDbConfig.RetryConfig.builder()
.maxAttempts(3)
.build())
.build()
)
.databaseSwitchListener(event ->
System.out.println("Switched to: " + event.getEndpoint()))
.build();
cache, cacheConfig, clientConfig, commandExecutor, commandObjects, connectionProvider, jsonObjectMapper, keyPreProcessor, poolConfig, searchDialect| Constructor and Description |
|---|
MultiDbClientBuilder() |
| Modifier and Type | Method and Description |
|---|---|
protected CommandExecutor |
createDefaultCommandExecutor()
Creates a default command executor based on the current configuration.
|
protected ConnectionProvider |
createDefaultConnectionProvider()
Creates a default connection provider based on the current configuration.
|
MultiDbClientBuilder<C> |
databaseSwitchListener(java.util.function.Consumer<DatabaseSwitchEvent> listener)
Sets a listener for database switch events.
|
MultiDbClientBuilder<C> |
multiDbConfig(MultiDbConfig config)
Sets the multi-database configuration.
|
protected MultiDbClientBuilder<C> |
self()
Returns the concrete builder instance for method chaining.
|
protected void |
validateSpecificConfiguration()
Validates the builder-specific configuration.
|
applyCommandObjectsConfiguration, build, cache, cacheConfig, clientConfig, commandExecutor, connectionProvider, createClient, createDefaultClientConfig, createDefaultCommandObjects, jsonObjectMapper, keyPreProcessor, poolConfig, searchDialect, validateCommonConfigurationpublic MultiDbClientBuilder<C> multiDbConfig(MultiDbConfig config)
This configuration controls circuit breaker behavior, retry logic, health checks, failback settings, and other resilience features. If not provided, default configuration will be used.
config - the multi-database configurationpublic MultiDbClientBuilder<C> databaseSwitchListener(java.util.function.Consumer<DatabaseSwitchEvent> listener)
The listener will be called whenever the client switches from one endpoint to another, providing information about the switch reason and the new active endpoint. This is useful for monitoring, alerting, and logging purposes.
listener - the database switch event listenerprotected MultiDbClientBuilder<C> self()
AbstractClientBuilderself in class AbstractClientBuilder<MultiDbClientBuilder<C>,C>protected ConnectionProvider createDefaultConnectionProvider()
AbstractClientBuildercreateDefaultConnectionProvider in class AbstractClientBuilder<MultiDbClientBuilder<C>,C>protected CommandExecutor createDefaultCommandExecutor()
AbstractClientBuildercreateDefaultCommandExecutor in class AbstractClientBuilder<MultiDbClientBuilder<C>,C>protected void validateSpecificConfiguration()
AbstractClientBuilderThis method is called by the generic build() method to validate configuration specific to each builder type. Implementations should call validateCommonConfiguration() and then perform their own specific validation.
validateSpecificConfiguration in class AbstractClientBuilder<MultiDbClientBuilder<C>,C>Copyright © 2025. All rights reserved.