toCommandMessage

fun <C : Any> C.toCommandMessage(id: String = generateGlobalId(), requestId: String? = null, aggregateId: String? = null, tenantId: String? = null, ownerId: String? = null, aggregateVersion: Int? = null, namedAggregate: NamedAggregate? = null, header: Header = DefaultHeader.empty(), createTime: Long = System.currentTimeMillis(), upstream: DomainEvent<*>? = null, ownerIdSameAsAggregateId: Boolean = false): 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

C

the type of the command

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)

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

See also

Throws

if no named aggregate can be determined


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

C

the type of the command body

See also