Class CircuitBreakerOpenException

  • All Implemented Interfaces:
    Serializable

    public class CircuitBreakerOpenException
    extends RocketRestException
    Exception thrown when a request is rejected due to an open circuit breaker.

    This exception indicates that the downstream service is considered unhealthy and requests are being fast-failed to prevent cascading failures. It provides timing information to help callers decide when to retry.

    Handling Circuit Open

    
     try {
         User user = client.get("/users/1", User.class);
     } catch (CircuitBreakerOpenException e) {
         long waitTime = e.getEstimatedMillisUntilReset();
    
         if (waitTime > 0) {
             System.out.println("Service unavailable, retry in " + waitTime + "ms");
             // Schedule retry after waitTime
         } else {
             // Circuit should be half-open soon, retry immediately
             System.out.println("Circuit may reset soon, retrying...");
         }
     }
     

    Using with Fluent API

    
     Result<User, ApiError> result = client.fluent().get("/users/1", User.class);
    
     result.match(
         user -> System.out.println("Success"),
         error -> {
             if (error.isCircuitOpen()) {
                 System.out.println("Circuit breaker is open");
             }
         }
     );
     
    Since:
    1.0.0
    Author:
    guinetik <guinetik@gmail.com>
    See Also:
    CircuitBreakerClient, RocketRestException, Serialized Form
    • Constructor Detail

      • CircuitBreakerOpenException

        public CircuitBreakerOpenException​(String message)
        Creates a new CircuitBreakerOpenException with the specified message.
        Parameters:
        message - The error message
      • CircuitBreakerOpenException

        public CircuitBreakerOpenException​(String message,
                                           long millisSinceLastFailure,
                                           long resetTimeoutMs)
        Creates a new CircuitBreakerOpenException with the specified message and timing information about when the circuit might reset.
        Parameters:
        message - The error message
        millisSinceLastFailure - Milliseconds since the last failure
        resetTimeoutMs - Milliseconds until the circuit will attempt to reset
      • CircuitBreakerOpenException

        public CircuitBreakerOpenException​(String message,
                                           Throwable cause,
                                           long millisSinceLastFailure,
                                           long resetTimeoutMs)
        Creates a new CircuitBreakerOpenException with the specified message, cause, and timing information about when the circuit might reset.
        Parameters:
        message - The error message
        cause - The cause of this exception
        millisSinceLastFailure - Milliseconds since the last failure
        resetTimeoutMs - Milliseconds until the circuit will attempt to reset
    • Method Detail

      • getMillisSinceLastFailure

        public long getMillisSinceLastFailure()
        Gets the milliseconds since the last failure that caused the circuit to open.
        Returns:
        milliseconds since the last failure, or 0 if not available
      • getResetTimeoutMs

        public long getResetTimeoutMs()
        Gets the configured timeout after which the circuit will try to reset.
        Returns:
        reset timeout in milliseconds, or 0 if not available
      • getEstimatedMillisUntilReset

        public long getEstimatedMillisUntilReset()
        Gets an estimated time in milliseconds until the circuit might reset. A negative value indicates the circuit should have already attempted to reset.
        Returns:
        estimated milliseconds until reset, or 0 if timing data is unavailable
      • getCause

        public Throwable getCause()
        Gets the underlying cause of the circuit opening. This may be null if the circuit was already open when the request was made.
        Overrides:
        getCause in class Throwable
        Returns:
        the cause exception that led to the circuit opening, or null if not available