Commit 8d1796f
[automatic failover] Add example for automatic failover (#3568)
* add DatabaseConfig.Builder
* healthCheckStrategySupplier now defaults to PingStrategy.DEFAULT in the builder
- When using the builder without setting healthCheckStrategySupplier: Health checks will use PingStrategy.DEFAULT
- When explicitly setting to null: Health checks will be disabled (as documented)
- When setting to a custom supplier: Uses the custom health check strategy
Example Usage:
// Uses PingStrategy.DEFAULT for health checks
DatabaseConfig config1 = DatabaseConfig.builder(uri)
.weight(1.0f)
.build();
// Explicitly disables health checks
DatabaseConfig config2 = DatabaseConfig.builder(uri)
.healthCheckStrategySupplier(null)
.build();
// Uses custom health check strategy
DatabaseConfig config3 = DatabaseConfig.builder(uri)
.healthCheckStrategySupplier(customSupplier)
.build();
* HealthCheckStrategySupplier.NO_HEALTH_CHECK instead null
* Remove DatabaseConfig constructors
// To create DatabaseConfig use provided builder
DatabaseConfig config = DatabaseConfig.builder(redisURI)
.weight(1.5f)
.clientOptions(options)
.circuitBreakerConfig(cbConfig)
.healthCheckStrategySupplier(supplier)
.build();
* remove redundant public modifiers
* Builder for CircuitBreakerConfig
// Minimal configuration with defaults
CircuitBreakerConfig config = CircuitBreakerConfig.builder().build();
// Custom configuration
CircuitBreakerConfig config = CircuitBreakerConfig.builder()
.failureRateThreshold(25.0f)
.minimumNumberOfFailures(500)
.metricsWindowSize(5)
.build();
// With custom tracked exceptions
Set<Class<? extends Throwable>> customExceptions = new HashSet<>();
customExceptions.add(RuntimeException.class);
CircuitBreakerConfig config = CircuitBreakerConfig.builder()
.failureRateThreshold(15.5f)
.minimumNumberOfFailures(200)
.trackedExceptions(customExceptions)
.metricsWindowSize(3)
.build();
* enforce min window size of 2s
* tracked exceptions should not be null
* add convenience methods for Tracked Exceptions
//Combine add and remove
CircuitBreakerConfig config = CircuitBreakerConfig.builder()
.addTrackedExceptions(MyCustomException.class)
.removeTrackedExceptions(TimeoutException.class)
.build();
// Replace all tracked exceptions
Set<Class<? extends Throwable>> customExceptions = new HashSet<>();
customExceptions.add(RuntimeException.class);
customExceptions.add(IOException.class);
CircuitBreakerConfig config = CircuitBreakerConfig.builder()
.trackedExceptions(customExceptions)
.build();
* remove option to configure per database clientOptions till #3572 is resolved
* Disable health checks in test configs to isolate circuit breaker testing
Configure DB1, DB2, and DB3 with NO_HEALTH_CHECK to prevent health check
interference when testing circuit breaker failure detection.
* forma
* clean up
* address review comments (Copilot)
* Add example for automatic failover
* Use builders
* shutdown primary instance
* remove unused imports
* Update src/test/java/io/lettuce/examples/AutomaticFailover.java
Co-authored-by: atakavci <a_takavci@yahoo.com>
* revert accidentally disabled user timeout config
---------
Co-authored-by: ggivo <ivo.gaydazhiev@redis.com>
Co-authored-by: atakavci <a_takavci@yahoo.com>1 parent bad065d commit 8d1796f
1 file changed
+166
-0
lines changedLines changed: 166 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
0 commit comments