Skip to main content

Domain events

Every event this context publishes or consumes, with the full CloudEvents type. The contract is apis/asyncapi.yaml; the envelope (specversion 1.0, id, source, type, subject, time, datacontenttype application/json, dataschema) is built only by internal/adapters/kafka/cloudevents. Payload fields are snake_case and timestamps are RFC 3339 UTC. The catalogue itself is ADR 0004; TestEventCatalogueMatchesContract fails CI when the two drift.

Published​

dataschema is urn:warehouse:returns-processing:events:<EventName>:v1; source is /warehouse/returns-processing; the Kafka header content-type is application/cloudevents+json; charset=UTF-8; the Kafka key is the subject, so all events of one aggregate stay ordered on one partition. Everything leaves through the transactional outbox (ADR 0005).

EventFull typeKey and subjectRaised by
ReturnAuthorizedcom.warehouse.wms.returns-processing.returnauthorization.ReturnAuthorizedrmaIdAuthorizeReturn (REST POST /returns)
ReturnAuthorizationRejectedcom.warehouse.wms.returns-processing.returnauthorization.ReturnAuthorizationRejectedrmaIdthe domain's Reject; no v1 publisher path — a refusal persists nothing (see the note below)
ReturnReceiptOpenedcom.warehouse.wms.returns-processing.returnreceipt.ReturnReceiptOpenedreceiptIdOpenReturnReceipt (REST POST /returns/{rmaId}/receipts)
UnexpectedReturnReceivedcom.warehouse.wms.returns-processing.returnreceipt.UnexpectedReturnReceivedreceiptIdOpenReturnReceipt, one per UNEXPECTED line
ReturnLineInspectedcom.warehouse.wms.returns-processing.returnreceipt.ReturnLineInspectedreceiptIdInspectReturnLine
DispositionDecidedcom.warehouse.wms.returns-processing.disposition.DispositionDecideddispositionIdInspectReturnLine (policy) or OverrideDisposition
ReturnLineStagedcom.warehouse.wms.returns-processing.disposition.ReturnLineStageddispositionIda RESTOCK disposition, exactly once

Payloads​

Eventdata fields
ReturnAuthorizedrma_id, order_id, line_no, sku, quantity, site_id, reason_code, window_ends_at, authorized_at
ReturnAuthorizationRejectedrma_id, order_id, line_no, sku, quantity, rejection_code (LINE_NOT_MANIFESTED, RETURN_WINDOW_EXPIRED, OPEN_RMA_EXISTS, QUANTITY_EXCEEDS_POLICY), rejected_at
ReturnReceiptOpenedreceipt_id, rma_id (nullable), site_id, opened_at, lines:[{line_no, sku, quantity, rma_id (nullable)}]
UnexpectedReturnReceivedreceipt_id, line_no, sku, quantity, site_id, received_at
ReturnLineInspectedreceipt_id, line_no, sku, quantity, grade (A/B/C/SCRAP), reason_codes:[], inspected_at
DispositionDecideddisposition_id, receipt_id, line_no, sku, quantity, grade, outcome (RESTOCK/REFURBISH/LIQUIDATE/DISPOSE/RTV), policy_version, supersedes (nullable), reason (nullable), decided_at
ReturnLineStagedreceipt_id, line_no, sku, quantity, condition ("Good"), received_at, rma_id (nullable), disposition_id, site_id

Publisher-path note: ReturnAuthorizationRejected is raised by the domain's Reject and sits in the catalogue (ADR 0004), but no v1 code path publishes it: AuthorizeReturn decides synchronously in one transaction and a refusal returns the typed domain error — nothing is persisted, nothing is published. The event gains a publisher with a future async decision path (ADR 0002 keeps REQUESTED for it).

Payload rules: ReturnLineStaged.data is inbound-receiving's ReceiptLineReceived shape plus rma_id, disposition_id, site_id — inventory-storage consumes it into its staged-receipt use case (its ADR 0044), and disposition_id is the downstream idempotency key. rma_id is an explicit null when the restocked line was UNEXPECTED (no RMA), as everywhere else in the catalogue, never an empty string. DispositionDecided.supersedes/reason are null on a policy decision and mandatory on an override. A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

An analytics mirror (warehouse.returns-processing.analytics, same type and id per occurrence) is built (ADR 0007): the relay writes both messages in one pass and the service's own projector is the consumer.

Consumers of the published events, checked on each sibling's origin/develop (2026-10-21): inventory-storage consumes ReturnLineStaged (built, its ADR 0044); exception-management consumes UnexpectedReturnReceived to open a problem-solve case (built on its develop). Nothing else consumes the topic today.

Consumed​

Full typeTopicKeyFields usedHandler
com.warehouse.wms.product-master.product.ProductClassifiedwarehouse.product-master.eventsskusku, handling_tags, temperature_class, dot_hazard_class, version (+ forced outcome)classifications consumer, ApplyProductClassification — apply only when version > stored
com.warehouse.wes.order-management.order.OrderAllocatedwarehouse.order-management.eventsorderIdorder_id, lines[{line_no, sku, ...}] — NO quantityorder lines consumer, ApplyAllocations — one claim per event covering every line
com.warehouse.wes.order-management.order.OrderPartiallyAllocatedwarehouse.order-management.eventsorderIdsame shape, only the allocated linesorder lines consumer — refreshes only its own lines
com.warehouse.wes.fulfillment-execution.package.PackageManifestedwarehouse.fulfillment.eventspackageIdpackage_id, order_ref (reversed {order_id}-line-{line_no}), envelope time → manifested_atmanifest consumer, ApplyManifest

Every other type on those topics is ignored (commit past); a message that is not a valid CloudEvent is WARN-logged and skipped; a payload that can never apply is poison and dead-letters. Dedupe on the CloudEvents id — the claim is written in the same transaction as the effect, and the offset commits only after success. Consumer groups: PRODUCT_CLASSIFICATION_CONSUMER_GROUP, ORDER_LINES_CONSUMER_GROUP, MANIFEST_CONSUMER_GROUP.

Example: ReturnLineStaged​

This is the golden file internal/adapters/outbound/kafka/testdata/return_line_staged.golden.json — the exact bytes the encoder test pins (one golden file per published type):

{
"specversion": "1.0",
"id": "4e7c2f9b-6a13-4d58-9c8e-3b5f1a2d7e94",
"source": "/warehouse/returns-processing",
"type": "com.warehouse.wms.returns-processing.disposition.ReturnLineStaged",
"subject": "disp-1",
"time": "2026-10-21T10:06:00Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:returns-processing:events:ReturnLineStaged:v1",
"data": {
"receipt_id": "rcpt-1",
"line_no": 1,
"sku": "SKU-BOOK-0001",
"quantity": 2,
"condition": "Good",
"received_at": "2026-10-21T10:00:00Z",
"rma_id": "rma-1",
"disposition_id": "disp-1",
"site_id": "site-1"
}
}