toCommandMessage

fun <C : Any> C.toCommandMessage(id: String = generateGlobalId(), requestId: String? = null, aggregateId: String? = null, tenantId: String? = null, ownerId: String? = null, spaceId: SpaceId? = null, aggregateVersion: Int? = null, namedAggregate: NamedAggregate? = null, header: Header = DefaultHeader.empty(), createTime: Long = System.currentTimeMillis(), upstream: DomainEvent<*>? = null, ownerIdSameAsAggregateId: Boolean = false, messagePropagator: MessagePropagators = MessagePropagators.DEFAULT): CommandMessage<C>

Converts any object to a CommandMessage using reflection and metadata.

This extension function analyzes the command object's class to extract metadata and construct a properly configured CommandMessage. It uses command metadata to determine aggregate targeting, property getters, and command characteristics.

Return

a properly configured CommandMessage

Parameters

id

unique identifier for the command message (auto-generated if not provided)

requestId

request identifier for tracking (defaults to id)

aggregateId

target aggregate instance ID (optional, extracted from command if available)

tenantId

tenant identifier (optional, extracted from command if available)

ownerId

owner identifier (optional, extracted from command if available)

spaceId

space identifier (optional); ignored, in favour of the default space, when the target aggregate is known here and is not spaced (@Spaced)

aggregateVersion

expected aggregate version (optional, extracted from command if available)

namedAggregate

named aggregate information (optional, extracted from command if available)

header

message headers (default empty)

createTime

creation timestamp (default current time)

upstream

upstream domain event (optional)

ownerIdSameAsAggregateId

whether owner ID should match aggregate ID

messagePropagator

propagates upstream's context into header (default: MessagePropagators.DEFAULT)

Type Parameters

C

the type of the command

See also

Throws

if no named aggregate can be determined


fun <C : Any> CommandBuilder.toCommandMessage(messagePropagator: MessagePropagators = MessagePropagators.DEFAULT): CommandMessage<C>

Converts a CommandBuilder to a CommandMessage.

This extension function takes all the properties configured in the CommandBuilder and creates a corresponding CommandMessage using the same logic as the command object's toCommandMessage method.

Return

a CommandMessage with all builder properties applied

Parameters

messagePropagator

propagates the builder's upstream context into its header

Type Parameters

C

the type of the command body

See also