Skip to main content

Domain events

Synced from inbound-receiving

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.

DockAppointment moved (ADR 0019); the four types are gone (ADR 0022)

The dock appointment is owned by dock-scheduling since ADR 0019. This context no longer raises the four dockappointment.DockAppointment* types (Booked, CheckedIn, Cancelled, Completed): ADR 0022 removed the api republish-appointments backfill, the legacy encoders and the domain Replay, and retired the four types from apis/asyncapi.yaml on both channels, so the integration topic carries asn.* and receipt.* types only. What this context keeps is a read-only local copy fed by dock-scheduling's DockAppointmentBooked, DockAppointmentCancelled, DockAppointmentRescheduled and DockAppointmentDoorReassigned (a different prefix, dock-scheduling.dockappointment; see Consumed below). Where other DDD pages still describe the appointment commands, rules or events, read them as the pre-transfer design; those pages are not yet rewritten.

Every event this context publishes or consumes. All are CloudEvents 1.0 in structured content mode (internal/adapters/kafka/cloudevents: the whole event is the JSON message value, Kafka header content-type: application/cloudevents+json; charset=UTF-8). Payload fields come from apis/asyncapi.yaml and the payload structs in internal/adapters/outbound/kafka/encoder.go; the event catalogue summarises the AsyncAPI file and ADR 0004 is the type catalogue (checked against the AsyncAPI file by TestEventCatalogueMatchesContract).

Published​

Raised by the aggregates (internal/domain/asn/events.go, internal/domain/receipt/events.go), encoded by the encoder (internal/adapters/outbound/kafka/encoder.go, payload structs in encoder_payloads.go) and inserted into outbox_events inside the use case's unit of work; the relay in cmd/api publishes them. Common attributes: source=/warehouse/inbound-receiving, time = domain occurred-at (UTC), datacontenttype=application/json, dataschema=urn:warehouse:inbound-receiving:events:<EventName>:v1. Topic warehouse.inbound-receiving.events for all eight (the <entity> segment is asn or receipt: asnRow and receiptRow in the encoder reject every other event, and apis/asyncapi.yaml declares exactly these eight on the integration channel). The partitioner is the Hash balancer on the Kafka key.

Full CloudEvents typesubject / Kafka keyProducer use casePayload (data)Known consumers
com.warehouse.wms.inbound-receiving.asn.ASNRegisteredasn_number / asn_numberRegisterAsnasn_number, supplier_ref, owner_ref?, expected_arrival?, lines[] = {line_no, sku, expected_qty}, cartons[]?dock-scheduling (ASN_CONSUMER_GROUP), yard-management (INBOUND_RECEIVING_CONSUMER_GROUP)
com.warehouse.wms.inbound-receiving.asn.ASNCancelledasn_number / asn_numberCancelAsnasn_number, reason?dock-scheduling, yard-management (same groups)
com.warehouse.wms.inbound-receiving.receipt.ReceiptOpenedreceipt_id / asn_numberOpenReceiptreceipt_id, asn_number, appointment_id?, door_code?, opened_atyard-management
com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceivedreceipt_id / asn_numberReceiveLine, ReceiveScan (a case or each scan)receipt_id, asn_number, line_no, sku, quantity, condition (Good or Damaged), received_at, owner_ref?, pack_gtin?, cases?, sscc?inventory-storage (INBOUND_RECEIPT_CONSUMER_GROUP, books Good only)
com.warehouse.wms.inbound-receiving.receipt.ReceiptCartonReceivedreceipt_id / asn_numberReceiveScan (a carton accepted; identity only, books no quantity)receipt_id, asn_number, owner_ref?, sscc?, parent_sscc?, sealed, lpn, contents[] = {line_no, sku, gtin, qty, lot?, expiry?, condition}, received_atinventory-storage, network-fulfillment (INBOUND_RECEIPT_CONSUMER_GROUP in each)
com.warehouse.wms.inbound-receiving.receipt.CartonDiscrepancyRaisedreceipt_id / asn_numberReceiveScan (a refused scan, one event per finding) and CloseReceipt (a MissingCarton finding for a manifest carton never accepted)receipt_id, sscc?, kind, expected?, actual?, atexception-management (CARTON_DISCREPANCY_CONSUMER_GROUP), network-fulfillment
com.warehouse.wms.inbound-receiving.receipt.ReceiptClosedreceipt_id / asn_numberCloseReceiptreceipt_id, asn_number, closed_at, discrepancies[] = {line_no, sku, kind, expected_qty, received_qty, damaged_qty}yard-management, network-fulfillment
com.warehouse.wms.inbound-receiving.receipt.ReceiptStowCompletedreceipt_id / asn_numberApplyVisitCheckedIn, ApplyContainerStowed, CloseReceipt (whichever completes the evidence; ADR 0021)receipt_id, asn_number, appointment_id, arrived_at, closed_at, stowed_at, dock_to_stock_seconds, carton_countnone yet (the projector folds the analytics copy)

? marks a field omitted when unset. The line-level discrepancy kind on ReceiptClosed is Short, Over or Damaged; the kind on CartonDiscrepancyRaised is one of the carton kinds (UnexpectedCarton, MissingCarton, DuplicateSscc, UnknownGtin, CaseQtyMismatch, MixedCaseDeclaredAsCasePack, UnlabelledCarton, CartonOverLimit, MixedCartonContentMismatch; cartonKinds in internal/domain/receipt/carton_findings.go). discrepancies is present and empty ([]) when everything matched, and a line can appear once per kind; received_qty is good + damaged. Every receipt event, and both ASN events, is keyed by asn_number, so everything that happens while one ASN is received stays ordered on one partition. The four dockappointment.DockAppointment* types are not in this table because nothing raises them any more (ADR 0022); the known-consumer column was read from the dispatch code (full-type constants) on each sibling's origin/develop on 2026-11-10, and no sibling code dispatches on them. A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

Example (the handover message):

{"specversion":"1.0","id":"3f8f6c2e-9b1a-4d6e-8a52-0c7d1e4b9a10","source":"/warehouse/inbound-receiving","type":"com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceived","subject":"rcpt-123e4567-e89b-12d3-a456-426614174000","time":"2026-10-08T14:00:00Z","datacontenttype":"application/json","dataschema":"urn:warehouse:inbound-receiving:events:ReceiptLineReceived:v1","data":{"receipt_id":"rcpt-123e4567-e89b-12d3-a456-426614174000","asn_number":"ASN-1001","line_no":1,"sku":"SKU-1","quantity":40,"condition":"Good","received_at":"2026-10-08T14:00:00Z"}}

Consumed​

Full CloudEvents typeTopicConsumerGroup envEffect
com.warehouse.wms.product-master.product.ProductRegisteredwarehouse.product-master.eventsProductConsumer → ApplyProductRegisteredPRODUCT_CONSUMER_GROUP (required)upsert the SKU into known_skus (uses data.sku only)
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredwarehouse.facility.eventsDockDoorConsumer → ApplyLocationSlotRegisteredDOCK_DOOR_CONSUMER_GROUP (required)upsert into dock_doors when role=Dock and dockFlow is Inbound or Both; ignore otherwise
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedwarehouse.facility.eventsDockDoorConsumer → ApplyLocationSlotDecommissionedDOCK_DOOR_CONSUMER_GROUPdelete the row for locationCode; a code that is not a door is a no-op
com.warehouse.wms.product-master.product.ProductPackLevelDeclaredwarehouse.product-master.eventsPackagingConsumer → ApplyPackLevelDeclaredPACKAGING_CONSUMER_GROUP (required)upsert the declared pack level into the packaging view
com.warehouse.wms.product-master.product.ProductPackLevelRetiredwarehouse.product-master.eventsPackagingConsumer → ApplyPackLevelRetiredPACKAGING_CONSUMER_GROUPretire the pack level in the packaging view
com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentBookedwarehouse.dock-scheduling.eventsDockAppointmentConsumer → ApplyDockAppointmentBookedDOCK_APPOINTMENT_CONSUMER_GROUP (required)upsert the appointments copy when direction=INBOUND (ADR 0019); outbound is ignored
com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentCancelledwarehouse.dock-scheduling.eventsDockAppointmentConsumer → ApplyDockAppointmentCancelledDOCK_APPOINTMENT_CONSUMER_GROUPmark the stored appointment cancelled
com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentRescheduledwarehouse.dock-scheduling.eventsDockAppointmentConsumer → ApplyDockAppointmentRescheduledDOCK_APPOINTMENT_CONSUMER_GROUPmove the copy's door and window (ADR 0020)
com.warehouse.wms.dock-scheduling.dockappointment.DockAppointmentDoorReassignedwarehouse.dock-scheduling.eventsDockAppointmentConsumer → ApplyDockAppointmentDoorReassignedDOCK_APPOINTMENT_CONSUMER_GROUPmove the copy's door (ADR 0020)
com.warehouse.wms.yard-management.yardvisit.VisitCheckedInwarehouse.yard-management.eventsVisitArrivalConsumer → ApplyVisitCheckedInVISIT_ARRIVAL_CONSUMER_GROUP (required)store the earliest arrived_at per appointment into visit_arrivals, then evaluate the dock-to-stock fact (ADR 0021)
com.warehouse.wms.inventory-storage.container.ContainerStowedwarehouse.inventory.eventsCartonStowConsumer → ApplyContainerStowedCARTON_STOW_CONSUMER_GROUP (required)store the earliest stow time per lpn into carton_stows, then evaluate the dock-to-stock fact (ADR 0021)

Facility-layout payloads are camelCase (locationCode, role, dockFlow); product-master's are snake_case. The six consumers always run (startConsumers in cmd/api/workers.go: product, packaging, dock door, dock appointment, visit arrival, carton stow). Each dispatches on the FULL type and ignores every other type on its topic, claims the CloudEvents id in processed_events in the SAME transaction as the effect, commits the offset only after that, and skips with a WARN anything that is not a valid CloudEvent. See Upstream contracts.

Analytics stream (internal)​

Since ADR 0006 every published event is also written, in the same unit of work and under the same CloudEvents id, type, subject and Kafka key, to warehouse.inbound-receiving.analytics (DLQ warehouse.inbound-receiving.analytics.dlq) with dataschema=urn:warehouse:inbound-receiving:analytics:<EventName>:v1 and a payload byte-for-byte equal to the integration payload (FanoutEncoder, internal/adapters/outbound/kafka/analytics_encoder.go). The topic therefore carries the same eight types as the integration topic; apis/asyncapi.yaml declares eight analytics messages. Its only consumer is this context's own inbound-projector (group ANALYTICS_CONSUMER_GROUP, default inbound-receiving-analytics); it is not an integration contract, so sibling contexts keep reading warehouse.inbound-receiving.events.

The projector folds ten kinds (report.Kinds()): six of the eight current types (ASNRegistered, ASNCancelled, ReceiptOpened, ReceiptLineReceived, ReceiptClosed, ReceiptStowCompleted) and the four historical dockappointment.DockAppointment* types. It does not fold ReceiptCartonReceived or CartonDiscrepancyRaised: an unknown type is ignored (a DEBUG line). The four historical types stay in the projector on purpose (ADR 0022): a stream is append-only, so a rebuild from the topic may still read them, and the appointments block of the receiving-performance report stays frozen. Nothing produces new ones.