Skip to content

Instantly share code, notes, and snippets.

@ndemengel
Last active April 26, 2020 11:42
Show Gist options
  • Save ndemengel/e62e9a4978fd2148a9d1488e5d09d45e to your computer and use it in GitHub Desktop.
Save ndemengel/e62e9a4978fd2148a9d1488e5d09d45e to your computer and use it in GitHub Desktop.
Commanq queue: configuring a queue
const val MY_QUEUE_NAME: String = "myServiceQueue"
@Configuration
class MyServiceQueueConfiguration {
@Bean(MY_QUEUE_NAME)
fun myServiceQueue(commandExecutionQueueFactory: CommandExecutionQueueFactory) =
commandExecutionQueueFactory.createQueue(
MY_QUEUE_NAME,
// optionally redefine part or totality of the default policy
DEFAULT_EXECUTION_POLICY.copy(
concurrency = 4,
delayBeforeConsideringTask = Duration.ofSeconds(5),
maxRetriesBeforeQuarantine = 10,
// optional, none by default
rateLimits = RateLimits(
2300 executionsOver Duration.ofMinutes(15),
4500 executionsOver Duration.ofMinutes(30),
8800 executionsOver Duration.ofHours(1)
),
// optional, none by default
circuitBreaking = CircuitBreaking(
failureRateThreshold = 0.5,
windowDuration = Duration.ofMinutes(10),
// will tell that some exceptions are to be considered as provider failures
considerExceptionAsFailureIf = someExceptionPredicate()
)
),
// optional, a probe that will be queried to know whether to pause task consumption
// (may query a feature flag, a state defined via some UI, etc.)
somePauseProbe()
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment