ores.cpp.nats-event-registrar.nats_event_registrar_implementation
Table of Contents
This page is the node for the ores.cpp.nats-event-registrar.nats_event_registrar_implementation archetype in the codegen
physical-space address graph. Its title is its MASD address; it generates one
output artefact and owns the mustache source below, tangled to the sibling
.mustache consumed by generator.py. Edit this document, then run the
tangle (compass build --direct tangle_codegen_templates).
Summary
Implements register_<entity>_event_mapping(): registers the entity's
Postgres NOTIFY channel with the postgres_event_source, then subscribes
the resulting in-process event_bus event and republishes it to NATS via
the shared ores.eventing.core publish_entity_event helper. The channel
name (sql_name_base, e.g. ores_refdata_purpose_types) matches
exactly what the notify_trigger SQL archetype emits in its
pg_notify() call — both derive from the same sql_name_base, the
:tablename:-derived base that keeps every object name within
PostgreSQL's 63-byte identifier limit, so they can never drift apart.
The ores.cpp.nats-event-registrar.nats_event_registrar_implementation archetype
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.nats-event-registrar.nats_event_registrar_implementation.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#include "ores.{{component_service}}/messaging/{{entity_singular}}_event_registrar.hpp"
#include "ores.eventing.api/domain/entity_change_event.hpp"
#include "ores.eventing.core/service/entity_event_publisher.hpp"
#include "ores.eventing.core/service/registrar.hpp"
#include "ores.{{component_include}}/eventing/{{entity_singular}}_changed_event.hpp"
namespace ores::{{component}}::service::messaging {
namespace {
namespace ev = ores::eventing;
}
[[nodiscard]] ev::service::subscription
register_{{entity_singular}}_event_mapping(ev::service::postgres_event_source& event_source,
ev::service::event_bus& event_bus,
ores::nats::service::client& nats) {
ev::service::registrar::register_mapping<{{component}}::eventing::{{entity_singular}}_changed_event>(
event_source, "ores.{{component}}.{{entity_singular}}", "{{sql_name_base}}");
return event_bus.subscribe<{{component}}::eventing::{{entity_singular}}_changed_event>(
[&nats](const {{component}}::eventing::{{entity_singular}}_changed_event& e) {
ev::service::publish_entity_event(
nats,
std::string(ev::domain::event_traits<{{component}}::eventing::{{entity_singular}}_changed_event>::name),
ev::domain::entity_change_event{.entity = "ores.{{component}}.{{entity_singular}}",
.timestamp = e.timestamp,
{{#primary_key.is_text}}
.entity_ids = e.{{primary_key.column}}s,
{{/primary_key.is_text}}
{{#primary_key.is_uuid}}
.entity_ids = e.{{entity_singular_short}}_ids,
{{/primary_key.is_uuid}}
.tenant_id = e.tenant_id});
});
}
} // namespace ores::{{component}}::service::messaging
{{/domain_entity}}
See also
- Parent facet: ores.cpp.nats-event-registrar
- Template variable reference
- ores.cpp.nats-event-registrar.nats_event_registrar_header — the header this implements.
- ores.sql.schema.notify_trigger — the SQL side of this pipeline; channel name must match.