Interface QueueCircuitBreaker
-
- All Known Implementing Classes:
QueueCircuitBreakerImpl
public interface QueueCircuitBreakerThe QueueCircuitBreaker monitors the queue activity and protects the system from too much load when circuits/endpoints are not reachable.- Author:
- https://github.com/mcweba [Marc-Andre Weber]
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description io.vertx.core.Future<Void>closeAllCircuits()Closes all non-closed circuits.io.vertx.core.Future<Void>closeCircuit(HttpRequest queuedRequest)Closes the circuit representing the queued request.io.vertx.core.Future<QueueCircuitState>handleQueuedRequest(String queueName, HttpRequest queuedRequest)Handles a queued request by checking the currentQueueCircuitStateof the corresponding circuit.booleanisCircuitCheckEnabled()Check whether the circuit check is enabled.booleanisStatisticsUpdateEnabled()Check whether the statistics update is enabled.io.vertx.core.Future<Void>lockQueue(String queueName, HttpRequest queuedRequest)Locks the queue having the provided queueName by calling the vertx-redisques API.io.vertx.core.Future<Void>reOpenCircuit(HttpRequest queuedRequest)Re-Opens the (half-open) circuit representing the provided queued request again.io.vertx.core.Future<Long>setOpenCircuitsToHalfOpen()Changes the status of all circuits having a status equalsQueueCircuitState.OPENtoQueueCircuitState.HALF_OPEN.io.vertx.core.Future<String>unlockNextQueue()Unlocks the next queue in-line.io.vertx.core.Future<String>unlockQueue(String queueName)Unlocks the queue having the provided queueName by calling the vertx-redisques API.io.vertx.core.Future<Long>unlockSampleQueues()Unlocks a sample queue of all circuits having a status equalsQueueCircuitState.HALF_OPEN.io.vertx.core.Future<Void>updateStatistics(String queueName, HttpRequest queuedRequest, QueueResponseType queueResponseType)Updates the statistics of the corresponding circuit based on the provided request to execute.
-
-
-
Method Detail
-
handleQueuedRequest
io.vertx.core.Future<QueueCircuitState> handleQueuedRequest(String queueName, HttpRequest queuedRequest)
Handles a queued request by checking the currentQueueCircuitStateof the corresponding circuit. When theQueueCircuitStateof the corresponding circuit equalsQueueCircuitState.OPEN, the provided queueName will be locked.- Parameters:
queueName- the name of the queuequeuedRequest- the queued request- Returns:
- returns a
QueueCircuitStaterepresenting the current status of the circuit
-
updateStatistics
io.vertx.core.Future<Void> updateStatistics(String queueName, HttpRequest queuedRequest, QueueResponseType queueResponseType)
Updates the statistics of the corresponding circuit based on the provided request to execute.
Updating the statistics includes the following steps:
- Record queuedRequest as failed when queueResponseType equals
QueueResponseType.FAILURE - Record queuedRequest as success when queueResponseType equals
QueueResponseType.SUCCESS - Calculate failRatio based on fail/success records
- Change status of corresponding circuit to 'OPEN' when failRatio threshold is reached
- Parameters:
queueName- the name of the queuequeuedRequest- the queued requestqueueResponseType- theQueueResponseTyperepresenting the execution result of the queuedRequest- Returns:
- returns a void future when statistics could be updated successfully.
- Record queuedRequest as failed when queueResponseType equals
-
isCircuitCheckEnabled
boolean isCircuitCheckEnabled()
Check whether the circuit check is enabled. The circuit check can be enabled/disabled with the 'circuitCheckEnabled' configuration property.- Returns:
- returns true when circuit check is enabled, false otherwise
-
isStatisticsUpdateEnabled
boolean isStatisticsUpdateEnabled()
Check whether the statistics update is enabled. The statistics update can be enabled/disabled with the 'statisticsUpdateEnabled' configuration property.- Returns:
- returns true when statistics update is enabled, false otherwise
-
lockQueue
io.vertx.core.Future<Void> lockQueue(String queueName, HttpRequest queuedRequest)
Locks the queue having the provided queueName by calling the vertx-redisques API. Additionally, marks the queueName as a locked queue of the circuit representing the provided queuedRequest.- Parameters:
queueName- the name of the queuequeuedRequest- the queued request- Returns:
- returns a void future when the queue could be locked successfully through vertx-redisques and also successfully marked as a locked queue of the circuit.
-
unlockQueue
io.vertx.core.Future<String> unlockQueue(String queueName)
Unlocks the queue having the provided queueName by calling the vertx-redisques API.- Parameters:
queueName- the name of the queue- Returns:
- returns a string future holding the name of the queue when successfully unlocked. Also returns the name of the queue (as failureMessage) when the unlocking failed.
-
unlockNextQueue
io.vertx.core.Future<String> unlockNextQueue()
Unlocks the next queue in-line. Does nothing when there's no next queue to unlock. Returns anullstring in this case.- Returns:
- returns a string future holding the name of the queue which was successfully unlocked. Also returns the name
of the queue (as failureMessage) when the next queue could not be unlocked. Returns a
nullstring when no queue was available to unlock.
-
closeCircuit
io.vertx.core.Future<Void> closeCircuit(HttpRequest queuedRequest)
Closes the circuit representing the queued request.
Closing the circuit includes the following steps:
- Clear statistics of this circuit
- Reset failRatio of this circuit to zero
- Set status of this circuit to 'CLOSED'
- Unlock all queues related to this circuit
- Parameters:
queuedRequest- the queued request- Returns:
- returns a void future when circuit could be closed successfully.
-
closeAllCircuits
io.vertx.core.Future<Void> closeAllCircuits()
Closes all non-closed circuits.
Closing all non-closed circuits includes the following steps:
- Clear statistics of all non-closed circuits
- Reset failRatio of all non-closed circuits to zero
- Set status of all non-closed circuits to 'CLOSED'
- Unlock all queues related to all non-closed circuits
- Returns:
- returns a void future when all non-closed circuits could be closed successfully.
-
reOpenCircuit
io.vertx.core.Future<Void> reOpenCircuit(HttpRequest queuedRequest)
Re-Opens the (half-open) circuit representing the provided queued request again. Circuits should be re-opened after a sample queue request was not successful.- Parameters:
queuedRequest- the queued request- Returns:
- returns a void future when the circuit representing the provided queued request could be re-opened successfully
-
setOpenCircuitsToHalfOpen
io.vertx.core.Future<Long> setOpenCircuitsToHalfOpen()
Changes the status of all circuits having a status equalsQueueCircuitState.OPENtoQueueCircuitState.HALF_OPEN.- Returns:
- returns a future holding the amount of circuits updated
-
unlockSampleQueues
io.vertx.core.Future<Long> unlockSampleQueues()
Unlocks a sample queue of all circuits having a status equalsQueueCircuitState.HALF_OPEN. The sample queues are always the queues which have not been unlocked the longest.- Returns:
- returns a future holding the amount of unlocked sample queues
-
-