-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[automatic failover] Add example for automatic failover #3568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+166
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e258449 to
97342ef
Compare
…he 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();
// To create DatabaseConfig use provided builder
DatabaseConfig config = DatabaseConfig.builder(redisURI)
.weight(1.5f)
.clientOptions(options)
.circuitBreakerConfig(cbConfig)
.healthCheckStrategySupplier(supplier)
.build();
// 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();
//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();
atakavci
approved these changes
Dec 10, 2025
Configure DB1, DB2, and DB3 with NO_HEALTH_CHECK to prevent health check interference when testing circuit breaker failure detection.
97342ef to
a5693a4
Compare
atakavci
approved these changes
Dec 11, 2025
Collaborator
atakavci
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: atakavci <a_takavci@yahoo.com>
ggivo
reviewed
Dec 11, 2025
Contributor
ggivo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The code example showcases how to use the current API.