SagaRegistry

Registry for managing multiple named, reusable saga templates.

A Saga instance is safe to Saga.execute more than once (its per-run tracking state is reset at the start of every execution), so storing one by name and re-running it is the main use case for this registry -- e.g. an "order-checkout" saga built once at startup and executed per order.

Example usage:

val registry = SagaRegistry.create()

val checkout = registry.getOrCreate<OrderResult>("order-checkout") {
step("Reserve inventory", action = { inventoryService.reserve(items) })
step("Charge payment", action = { paymentService.charge(amount) })
}

val result = checkout.execute()

Types

Link copied to clipboard
object Companion

Factory for SagaRegistry.

Functions

Link copied to clipboard
suspend fun <T> get(name: String): Saga<T>?

Gets an existing saga template by name.

Link copied to clipboard
suspend fun getNames(): Set<String>

Gets all saga template names in the registry.

Link copied to clipboard
suspend fun <T> getOrCreate(name: String, configure: SagaBuilder<T>.() -> Unit): Saga<T>

Gets an existing saga template or builds a new one from configure.

Link copied to clipboard
suspend fun remove(name: String): Saga<*>?

Removes a saga template from the registry.