AfterCommand

@OnMessage(functionKind = FunctionKind.COMMAND, defaultFunctionName = "afterCommand")
annotation class AfterCommand(val include: Array<KClass<*>> = [], val exclude: Array<KClass<*>> = [])

Marks a function to be executed after a command function completes.

Functions annotated with @AfterCommand are invoked after command processing finishes. If the function returns a non-null value, it will be appended to the event stream as a domain event.

This annotation enables post-command processing such as:

  • Publishing additional domain events

  • Triggering side effects

  • Updating related aggregates

  • Sending notifications

Example usage:

@AggregateRoot
class OrderAggregate {

@OnCommand
fun createOrder(command: CreateOrderCommand): OrderCreated {
// Create order logic
return OrderCreated(orderId, items)
}

@AfterCommand(include = [CreateOrderCommand::class])
fun afterCreateOrder(command: CreateOrderCommand): OrderNotificationSent? {
// Send notification after order creation
if (shouldSendNotification()) {
return OrderNotificationSent(orderId)
}
return null // No event if notification not needed
}
}

Parameters

include

Array of command types to listen for. Only commands of these types will trigger the function. If empty, all commands are included by default.

exclude

Array of command types to exclude from listening. Commands of these types will not trigger the function.

See also

for command handling functions

for the function kind this annotation targets

Properties

Link copied to clipboard
Link copied to clipboard