Order
Specifies the execution order for annotated elements.
This annotation controls the sequence in which handlers, processors, or components are executed when multiple candidates exist for the same operation. Lower values indicate higher priority (executed first).
Ordering is essential for:
Ensuring correct sequence of event processing
Controlling initialization order of components
Managing dependencies between processors
Implementing complex business workflows
Example usage:
@EventProcessor
class OrderProcessor {
@OnEvent
@Order(1) // Execute first
fun validateOrder(event: OrderCreated) {
// Validation logic
}
@OnEvent
@Order(2) // Execute after validation
fun processPayment(event: OrderCreated) {
// Payment processing
}
@OnEvent
@Order(after = [PaymentProcessor::class]) // Execute after PaymentProcessor
fun sendConfirmation(event: OrderCreated) {
// Send confirmation
}
}Parameters
The priority value. Lower numbers execute first. Common values: ORDER_FIRST (-2^31), ORDER_DEFAULT (0), ORDER_LAST (2^31-1)
Array of classes that this element should execute before. Useful for relative ordering without hard-coded values.
Array of classes that this element should execute after. Useful for relative ordering without hard-coded values.
See also
for the highest priority
for normal priority
for the lowest priority