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.

See also

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val aggregateId: String?

the target aggregate instance identifier (optional)

Link copied to clipboard
abstract val aggregateVersion: Int?

expected version for optimistic concurrency (optional)

Link copied to clipboard
abstract val body: Any

the command payload object

Link copied to clipboard
abstract val createTime: Long

timestamp when the command was created

Link copied to clipboard
abstract val header: Header

message headers for additional metadata

Link copied to clipboard
abstract val id: String
Link copied to clipboard

the named aggregate information (optional)

Link copied to clipboard
abstract val ownerId: String?

the owner identifier of the aggregate (optional)

Link copied to clipboard

whether owner ID should match aggregate ID

Link copied to clipboard
abstract val requestId: String?

unique identifier for the request (optional)

Link copied to clipboard
abstract val tenantId: String?

the tenant identifier for multi-tenancy (optional)

Link copied to clipboard
abstract val upstream: DomainEvent<*>?

the domain event that triggered this command (optional)

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 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.