How do I wire an entity into live NATS eventing?
The Postgres LISTEN/NOTIFY-to-NATS pipeline (a row change fires a channel notification, the service re-publishes it as a NATS event) used to be wired by hand per entity in each component's service/src/app/application.cpp: one #include, one register_mapping<T>() call, one event_bus.subscribe<T>() lambda. Codegen now generates that wiring; see ores.cpp.nats-event-registrar for the facet and Entity-composed registrars for the architecture pattern it mirrors.
Question
How do I wire a domain_entity into live NATS eventing instead of hand-wiring application.cpp?
Answer
Generate the per-entity event-mapping registrar:
./compass.sh codegen entity generate <entity-slug> --address ores.cpp.nats-event-registrar
This produces <entity>_event_registrar.hpp/cpp in the component's .service layer (not .core, since the pipeline depends on ores.eventing.core), declaring and defining register_<entity>_event_mapping(event_source, event_bus, nats). It registers the entity's Postgres channel (product_component_entity_plural, matching what the notify_trigger SQL archetype already emits) and republishes the resulting event to NATS via the shared ores::eventing::service::publish_entity_event helper.
Then wire it into the component's aggregator (e.g. ores::refdata::service::messaging::event_registrar::register_event_mappings, colocated with application.cpp) — a single hand-maintained line per entity, mirroring the request/response counterpart (ores::refdata::core::messaging::registrar::register_handlers):
subs.push_back(register_<entity>_event_mapping(event_source, event_bus, nats));
If application.cpp still hand-wires the entity (an #include + register_mapping<T>() call + event_bus.subscribe<T>() lambda), remove that block — the generated registrar replaces it exactly.
Before regenerating, check the entity's nats-eventing output isn't stale (compass codegen entity generate <entity-slug> --address ores.cpp.nats-eventing --diff). If it drifts, the changed-event's id field may rename (e.g. ids -> <entity>_ids), breaking any existing consumer of the old name — audit those first.
Script
./compass.sh codegen entity generate <entity-slug> --address ores.cpp.nats-event-registrar — thin wrapper over ores.codegen's generate.py resolving the entity model, the ores.cpp.nats-event-registrar facet's two archetypes, and the component_service_dir output path.
Tested by
Manual: cross-client NATS eventing verified for purpose_type (PR #1451, #1459) — edit in one Qt client, confirm the other client's list updates live without a manual refresh.
See also
- ores.cpp.nats-event-registrar — the facet this recipe drives.
- ores.cpp.nats-sub-registrar — the request/response counterpart.
- How do I regenerate the NATS eventing layer for an entity? — regenerating the changed-event struct itself.