@Experimental public class MultiDbConnectionProvider extends java.lang.Object implements ConnectionProvider
ConnectionProvider which supports multiple database endpoints each with their own isolated connection pool. With this ConnectionProvider users can seamlessly failover to Disaster Recovery (DR), Backup, and Active-Active database(s) by using simple configuration which is passed through from Resilience4j - docs
Support for manual failback is provided by way of setActiveDatabase(Endpoint)
| Modifier and Type | Class and Description |
|---|---|
static class |
MultiDbConnectionProvider.Database |
| Constructor and Description |
|---|
MultiDbConnectionProvider(MultiDbConfig multiDbConfig) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(MultiDbConfig.DatabaseConfig databaseConfig)
Adds a new database endpoint to the provider.
|
void |
assertOperability()
Asserts that the active database is operable.
|
boolean |
canIterateFrom(MultiDbConnectionProvider.Database iterateFrom)
Indicates the final database endpoint (connection pool), according to the pre-configured list
provided at startup via the MultiDbConfig, is unavailable and therefore no further failover is
possible.
|
void |
close() |
void |
forceActiveDatabase(Endpoint endpoint,
long forcedActiveDuration) |
Endpoint |
getActiveEndpoint()
Returns the active endpoint
Active endpoint is the one which is currently being used for all operations.
|
Connection |
getConnection() |
Connection |
getConnection(CommandArguments args) |
Connection |
getConnection(Endpoint endpoint) |
java.util.Map<?,Pool<Connection>> |
getConnectionMap() |
MultiDbConnectionProvider.Database |
getDatabase() |
MultiDbConnectionProvider.Database |
getDatabase(Endpoint endpoint) |
io.github.resilience4j.circuitbreaker.CircuitBreaker |
getDatabaseCircuitBreaker() |
java.util.Set<Endpoint> |
getEndpoints()
Returns the set of all configured endpoints.
|
java.util.List<java.lang.Class<? extends java.lang.Throwable>> |
getFallbackExceptionList() |
boolean |
isHealthy(Endpoint endpoint)
Returns the health state of the given endpoint
|
void |
onDatabaseSwitch(SwitchReason reason,
Endpoint endpoint,
MultiDbConnectionProvider.Database database) |
void |
remove(Endpoint endpoint)
Removes a database endpoint from the provider.
|
void |
setActiveDatabase(Endpoint endpoint) |
void |
setDatabaseSwitchListener(java.util.function.Consumer<DatabaseSwitchEvent> databaseSwitchListener) |
void |
validateTargetConnection(Endpoint endpoint)
Design decision was made to defer responsibility for cross-replication validation to the user.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPrimaryNodesConnectionMappublic MultiDbConnectionProvider(MultiDbConfig multiDbConfig)
public void add(MultiDbConfig.DatabaseConfig databaseConfig)
databaseConfig - the configuration for the new databaseJedisValidationException - if the endpoint already existspublic void remove(Endpoint endpoint)
endpoint - the endpoint to removeJedisValidationException - if the endpoint doesn't exist or is the last remaining
endpoint@VisibleForTesting public void assertOperability()
This method is called by the circuit breaker command executor before executing a command.
JedisFailoverException.JedisPermanentlyNotAvailableException - if the there is no operable database and the max
number of failover attempts has been exceeded.JedisFailoverException.JedisTemporarilyNotAvailableException - if the there is no operable database and the max
number of failover attempts has not been exceeded.public void validateTargetConnection(Endpoint endpoint)
public java.util.Set<Endpoint> getEndpoints()
public void setActiveDatabase(Endpoint endpoint)
public void forceActiveDatabase(Endpoint endpoint, long forcedActiveDuration)
public void close()
close in interface java.lang.AutoCloseablepublic Connection getConnection()
getConnection in interface ConnectionProviderpublic Connection getConnection(Endpoint endpoint)
public Connection getConnection(CommandArguments args)
getConnection in interface ConnectionProviderpublic java.util.Map<?,Pool<Connection>> getConnectionMap()
getConnectionMap in interface ConnectionProviderpublic MultiDbConnectionProvider.Database getDatabase()
@VisibleForTesting public MultiDbConnectionProvider.Database getDatabase(Endpoint endpoint)
public Endpoint getActiveEndpoint()
Active endpoint is the one which is currently being used for all operations. It can change at any time due to health checks, failover, failback, etc.
public boolean isHealthy(Endpoint endpoint)
endpoint - the endpoint to checkpublic io.github.resilience4j.circuitbreaker.CircuitBreaker getDatabaseCircuitBreaker()
public boolean canIterateFrom(MultiDbConnectionProvider.Database iterateFrom)
public void onDatabaseSwitch(SwitchReason reason, Endpoint endpoint, MultiDbConnectionProvider.Database database)
public void setDatabaseSwitchListener(java.util.function.Consumer<DatabaseSwitchEvent> databaseSwitchListener)
public java.util.List<java.lang.Class<? extends java.lang.Throwable>> getFallbackExceptionList()
Copyright © 2025. All rights reserved.