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).

1. 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.

2. 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_event_traits.hpp"
#include "ores.eventing.core/service/entity_event_publisher.hpp"
#include "ores.eventing.core/service/registrar.hpp"
#include "ores.{{component_include}}/eventing/{{entity_singular}}_event.hpp"
#include "ores.{{component_include}}/messaging/{{entity_singular}}_protocol.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) {
    // The trigger publishes on the table's own channel, and the mapping turns
    // what it says into this entity's event.
    event_source.register_entity_event_mapping<{{component}}::messaging::{{entity_singular}}_event>(
        "{{sql_name_base}}");

    return event_bus.subscribe<{{component}}::messaging::{{entity_singular}}_event>(
        [&nats](const {{component}}::messaging::{{entity_singular}}_event& e) {
            // One payload is addressed by three subjects, so the subject is
            // the collection's prefix and the action the event reports.
            ev::service::publish_entity_event(
                nats,
                ev::domain::event_subject<{{component}}::messaging::{{entity_singular}}_event>(
                    e.action),
                e);
        });
}

} // namespace ores::{{component}}::service::messaging
{{/domain_entity}}

3. See also

Emacs 29.3 (Org mode 9.6.15)