CommandMessage

Represents a command message that can be sent to an aggregate. This interface extends several other interfaces to provide a comprehensive set of properties and methods for handling commands within a domain-driven design (DDD) context.

The CommandMessage interface ensures that each command has a unique identifier, is associated with an aggregate, and can be copied. It also provides properties to manage the state and behavior of the command, such as whether it is a create command or if it allows the creation of a new aggregate.

Parameters

C

the type of the command payload

Properties

Link copied to clipboard
abstract override val aggregateId: AggregateId

Represents the unique identifier of the aggregate to which this command message is directed. This property is essential for identifying the specific aggregate that the command should be applied to, ensuring that commands are correctly routed and processed within the system.

Link copied to clipboard
abstract val aggregateName: String
Link copied to clipboard
abstract val aggregateVersion: Int?

Represents the version of the aggregate. This value is used to ensure that commands are applied to the correct version of an aggregate, which is essential for maintaining consistency and preventing conflicts in concurrent environments. A null value indicates that the version is not specified or relevant.

Link copied to clipboard
abstract val allowCreate: Boolean

Indicates whether the creation of a new aggregate is allowed by this command. This property is useful in scenarios where certain commands should only be applied to existing aggregates or when there are specific conditions under which an aggregate can be created.

Link copied to clipboard
abstract val body: C

The body of the message, containing the actual data payload of the message.

Link copied to clipboard
open override val commandId: String

Represents a unique identifier for a command. This identifier is crucial for ensuring that each command can be uniquely identified, which is particularly useful in scenarios where idempotency of commands needs to be guaranteed or when tracking and correlating commands across system boundaries.

Link copied to clipboard
abstract val contextName: String
Link copied to clipboard
abstract override val createTime: Long

The create time of the message, represented as a Unix timestamp in milliseconds.

Link copied to clipboard
abstract val header: Header

The header of the message, containing metadata about the message.

Link copied to clipboard
abstract val id: String

Represents a unique identifier for the implementing entity.

Link copied to clipboard
abstract val isCreate: Boolean

Indicates whether the command is intended for creating a new aggregate. This property is crucial in determining the nature of the command, specifically if it's meant to initialize a new aggregate instance.

Link copied to clipboard

Indicates whether the message is read-only, based on the state of the header.

Link copied to clipboard
abstract val isVoid: Boolean

Indicates whether the command message is a void command. A void command does not expect a return value and is typically used for operations that do not require a response.

Link copied to clipboard
abstract val name: String
Link copied to clipboard
abstract val ownerId: String

资源拥有者的唯一标识符

Link copied to clipboard
abstract val requestId: String

Represents a unique identifier for a request. This identifier is crucial for ensuring that each request can be uniquely identified, which is particularly useful in scenarios where idempotency of requests needs to be guaranteed or when tracking and correlating requests across system boundaries.

Functions

Link copied to clipboard
abstract fun copy(): CommandMessage<C>

复制当前对象 该方法用于创建并返回当前对象的一个复制品,确保复制品在修改时不会影响到原始对象

Link copied to clipboard

检查两个聚合根是否属于同一个上下文并具有相同的聚合根名称。

Link copied to clipboard
Link copied to clipboard
open fun withHeader(additionalSource: Map<String, String>): CommandMessage<C>

Adds all entries from the provided map to the message header and returns the message itself for method chaining.

open fun withHeader(key: String, value: String): CommandMessage<C>

Adds a key-value pair to the message header and returns the message itself for method chaining.

Link copied to clipboard

Marks the message as read-only and returns the message itself for method chaining.