CommandBuilder

Builder interface for constructing command messages.

CommandBuilder provides a fluent API for building command messages with all necessary properties like aggregate targeting, headers, and timing information. It supports method chaining for easy construction of complex command messages.

The builder exposes the command body, aggregate targeting, ownership and space information, optimistic-concurrency version, headers, creation time, and optional upstream event.

See also

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val aggregateId: String?
Link copied to clipboard
abstract val aggregateVersion: Int?
Link copied to clipboard
abstract val body: Any
Link copied to clipboard
abstract val createTime: Long
Link copied to clipboard
abstract val header: Header
Link copied to clipboard
abstract override val id: String
Link copied to clipboard
Link copied to clipboard
abstract val ownerId: String?
Link copied to clipboard
Link copied to clipboard
abstract val requestId: String?
Link copied to clipboard
abstract val spaceId: SpaceId?
Link copied to clipboard
abstract val tenantId: String?
Link copied to clipboard
abstract val upstream: DomainEvent<*>?

Functions

Link copied to clipboard
abstract fun aggregateId(aggregateId: String?): CommandBuilder

Sets the target aggregate instance identifier.

Link copied to clipboard
abstract fun aggregateVersion(aggregateVersion: Int?): CommandBuilder

Sets the expected aggregate version for optimistic concurrency control.

Link copied to clipboard
abstract fun body(body: Any): CommandBuilder

Sets the command body/payload.

Link copied to clipboard
open fun <C> bodyAs(): C

Casts the command body to the specified type.

Link copied to clipboard
abstract fun createTime(createTime: Long): CommandBuilder

Sets the creation timestamp for the command message.

Link copied to clipboard
abstract fun header(customize: (header: Header) -> Unit): CommandBuilder

Customizes the message header using a lambda function.

abstract fun header(header: Header): CommandBuilder

Sets the message header containing additional metadata.

Link copied to clipboard
abstract fun id(id: String): CommandBuilder

Sets the unique identifier for the command message.

Link copied to clipboard
open fun localFirst(localFirst: Boolean = true): CommandBuilder

Enables or disables local-first processing mode.

Link copied to clipboard
abstract fun namedAggregate(namedAggregate: NamedAggregate): CommandBuilder

Sets the named aggregate information for the command target.

Link copied to clipboard
abstract fun ownerId(ownerId: String?): CommandBuilder

Sets the owner identifier of the aggregate.

Link copied to clipboard
abstract fun ownerIdSameAsAggregateId(ownerIdSameAsAggregateId: Boolean): CommandBuilder

Sets whether the owner ID should be the same as the aggregate ID.

Link copied to clipboard
abstract fun requestId(requestId: String?): CommandBuilder

Sets the request identifier for tracking related commands.

Link copied to clipboard

Sets the request ID only if it's not already set.

Link copied to clipboard
abstract fun spaceId(spaceId: SpaceId?): CommandBuilder
Link copied to clipboard
Link copied to clipboard
abstract fun tenantId(tenantId: String?): CommandBuilder

Sets the tenant identifier for multi-tenancy support.

Link copied to clipboard

Sets the tenant ID only if it's not already set.

Link copied to clipboard

Converts a CommandBuilder to a CommandMessage.

Link copied to clipboard
abstract fun upstream(upstream: DomainEvent<*>): CommandBuilder

Sets the upstream domain event that triggered this command.