Skip to main content

Domain events

Synced from task-interleaving

This page is a copy of docs/docs/ddd/domain-events.md on develop, derived from that repository's code. Edit it there, then re-sync.

Every event the context raises, publishes or consumes: Go domain event, full CloudEvents type, topic, key, payload, producer and consumers. Payloads are snake_case, optional fields are omitted when unset, timestamps are RFC 3339 UTC. Contract: apis/asyncapi.yaml; catalogue: ADR 0004.

:::info Built end to end The domain events below are raised in code (internal/domain/stationtrip/events.go), turned into CloudEvents outbox rows by internal/adapters/outbound/events inside the use case's transaction, and published by the always-on outbox relay. The consumed events are handled by the always-on consumers in internal/adapters/inbound/kafka. See Integration for which sibling edges have a counterpart on the other side. :::

Raised by the domain​

Go eventRaised byCarriesWire type
stationtrip.HintIssuedStationTrip.IssueHintHeader{Station, Site, Version, At}, HintID, AfterTask, Origin, ExpiresAt, PolicyVersion, Candidates, SupersededHintIDInterleavingHintIssued
stationtrip.HintConsumedStationTrip.RecordClaimHeader, HintID, TaskID, Rank, DetourMInterleavingHintConsumed
stationtrip.HintExpiredStationTrip.ExpireHeader, HintID, ExpiresAtInterleavingHintExpired
none (package policy raises no event)the DeclarePolicy use case, through EventSink.PublishPolicyDeclaredsite, settings, version, declared-atInterleavingPolicyDeclared

HintIssued also names the hint it superseded, so persistence can close that row. A superseded hint has no event of its own. The domain names are HintIssued, HintConsumed and HintExpired; the published names carry the Interleaving prefix (internal/adapters/outbound/events/encoder.go).

Published​

Common envelope: specversion 1.0, source /warehouse/task-interleaving, datacontenttype application/json, id a UUID persisted with the outbox row (stable across relay retries), time the occurred-at instant in UTC, subject and Kafka key as below, Kafka header content-type: application/cloudevents+json; charset=UTF-8. dataschema is urn:warehouse:task-interleaving:<events|analytics>:<EventName>:v1.

Full typeTopic(s)subject and keyConsumers
com.warehouse.wes.task-interleaving.stationtrip.InterleavingHintIssuedwarehouse.task-interleaving.events, warehouse.task-interleaving.analyticsstation idnone built: fulfillment-execution's origin/develop has no consumer (its ADR 0049 and ADR 0050 list consuming it as out of scope); on the analytics topic also ti-projector (ADR 0008)
com.warehouse.wes.task-interleaving.stationtrip.InterleavingHintConsumedwarehouse.task-interleaving.analyticsstation idti-projector (own analytics read side, ADR 0008)
com.warehouse.wes.task-interleaving.stationtrip.InterleavingHintExpiredwarehouse.task-interleaving.analyticsstation idti-projector (ADR 0008)
com.warehouse.wes.task-interleaving.policy.InterleavingPolicyDeclaredwarehouse.task-interleaving.analyticssite idti-projector (ADR 0008; freshness only)

Payloads​

InterleavingHintIssued

FieldTypeNotes
hint_idstringhint- plus a unique suffix
station_idstring
site_idstring
after_task_idstringthe completed task this hint follows
origin_locationstringwhere the station stood
expires_atdate-timeissued_at + hint_ttl_seconds; issued_at is the CloudEvents time
policy_versionintegerat least 1
candidatesarray, at least 1, at most the policy's max_candidates{rank, task_id, task_type, location, detour_m}; ranked from 1 by detour_m then task_id; detour_m rounded to 0.1 m; location is the task's from_location

InterleavingHintConsumed: hint_id, station_id, site_id, task_id, rank, detour_m (those of the claimed candidate), consumed_at.

InterleavingHintExpired: hint_id, station_id, site_id, expires_at. The CloudEvents time is when the expiry was recorded, at or after expires_at.

InterleavingPolicyDeclared: site_id, max_detour_m, max_candidates, hint_ttl_seconds, eligible_task_types, vertical_weight, version, declared_at.

The integration and analytics rows of one occurrence share type and id; only dataschema differs. Both rows are written in the aggregate's transaction.

Consumed​

Full typeTopicKeyFields usedProducer status
com.warehouse.wes.fulfillment-execution.task.TaskAvailablewarehouse.fulfillment.eventstask idtask_id, task_type, site_id, from_location, to_location, required_capabilities[], priority_band (cpt and available_at are ignored)published since fulfillment-execution's ADR 0049, for RELOCATE and REPLENISH tasks (REPLENISH added by its ADR 0050; PICK, PACK, SLAM and REBIN are not announced)
com.warehouse.wes.fulfillment-execution.task.TaskClaimedwarehouse.fulfillment.eventstask idtask_id, task_type, station_id, claimed_atpublished on the integration topic for every task type, with claimed_at (the analytics-topic row is separate)
com.warehouse.wes.fulfillment-execution.task.TaskCompletedwarehouse.fulfillment.eventstask idtask_id, station_id (the producer requires task_id, station_id, work_unit_id)verified
com.warehouse.wms.facility-layout.zone.ZoneRegisteredwarehouse.facility.eventszoneIdzoneId, siteCode, zoneCodeverified
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredwarehouse.facility.eventslocationCodelocationCode, zoneIdverified
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedwarehouse.facility.eventslocationCodelocationCodeverified
com.warehouse.wms.facility-layout.locationslot.LocationGeometryUpdatedwarehouse.facility.eventslocationCodelocationCode, xM, yM, zMverified

A TaskAvailable with a task_type outside the six types a policy can make eligible (fulfillment-execution's enum also has DISPATCH and ARRIVAL) is stored but is never a candidate. facility-layout data also carries eventName, eventType and occurredAt, which are decoded and ignored. Every other type on these topics is ignored; dispatch is on the full type, never a suffix. A message that fails (transiently after 5 attempts, or because its payload can never be applied) goes to <topic>.dlq with x-dlq-* headers; see the Runbook.

Envelope helper​

internal/adapters/kafka/cloudevents builds and decodes every envelope:

FunctionBehaviour
Type(entity, eventName)com.warehouse.wes.task-interleaving.<entity>.<EventName> from the constants Subdomain = "wes" and Context = "task-interleaving"
DataSchema(stream, eventName, version)urn:warehouse:task-interleaving:<stream>:<EventName>:v<version>, streams events and analytics
New(Spec)Requires a non-empty subject, defaults Version below 1 to 1, sets specversion, id, source, type, subject, time (UTC), dataschema, datacontenttype and the data, validates, returns the structured-mode JSON
ContentTypeHeader()the Kafka header content-type: application/cloudevents+json; charset=UTF-8
Decode(value)Parses and validates; anything that is not a valid CloudEvents 1.0 event, including the retired flat envelope, returns an error wrapping ErrNotCloudEvent

Source: internal/adapters/kafka/cloudevents/cloudevents.go, cloudevents_test.go (TestDecodeRejectsLegacyFlatEnvelope).