CommandSender

class CommandSender(contracts: ContractDirectory, topics: SourceTopics)

Sends commands to the command topics of other contexts: how a saga's command reaches an aggregate of a context outside its own.

  • Type: the command's full type name (ctx.agg.Command) is the one the contracts give its class (ContractDirectory.commandTypeOf of the schema #/$defs/<binary name>): the target's Manifest, or a peer's contract, which reaches the service in the jar of the context's api module; a class several aggregates decide is named on the command's. A class no Manifest declares, or one of another aggregate than the command's, fails the send.

  • Topic and partition: wow.<ctx>.commands after the prefix (SourceTopics.commandsOf), in the partition the log's Partitioner gives the aggregate among the topic's partitions, which the target keeps equal to its log's, so the owner of the aggregate's log partition reads it; a creation that names no aggregate goes by its request instead (CommandMessages.laneOf), and the intake that reads it forwards it to the owner of the id it assigns. The partition count is read once per topic; a topic without partitions fails the send.

  • Durable ACCEPTED: send returns once the broker has acknowledged the message; it throws when it has not, and the caller retries with the same command, which the target does not decide twice.

  • Trace: the message carries the trace the sender runs in, which the target's intake continues.

Constructors

Link copied to clipboard
constructor(contracts: ContractDirectory, topics: SourceTopics)

Functions

Link copied to clipboard
suspend fun send(wire: CommandWire, wait: WaitContext? = null)

Sends wire, a command already in its wire form and named (a timer's), to its context's command topic, with wait.

suspend fun send(command: Command<*>, wait: WaitContext? = null, replyTo: ReplyTo? = null)

Sends command to its context's command topic, with wait and the replyTo of a rejection.

Link copied to clipboard
suspend fun sendAll(commands: List<Pair<Command<*>, ReplyTo?>>, wait: WaitContext? = null)

Sends commands, each with the ReplyTo of its receipt, to their contexts' command topics, with wait: those of one topic as one batch, in their order, so the commands to one aggregate keep theirs in its partition. Returns once the broker has acknowledged every batch; throws when it has not acknowledged one.

Link copied to clipboard
fun topicOf(context: String): String

The command topic of context, where its commands are sent.

Link copied to clipboard
fun typeOf(command: Command<*>): String

The full type name of command, as the contracts give its class; a system command by its system name: a lifecycle one or a schedule's wow.schedule.Set or Cancel, which every aggregate decides, or a ledger's wow.ledger.*, which the target's intake runs.