ores.cpp.nats-eventing.nats_changed_event_header
Table of Contents
Entity event type, its traits and the notify pipeline's conversion into it. nats-eventing profile.
See the Template variable reference for the complete list of available variables and their semantics.
1. Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_nats_changed_event.hpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.nats-eventing.nats_changed_event_header.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_{{component_include_upper}}_EVENTING_{{entity_singular_upper}}_EVENT_HPP
#define ORES_{{component_include_upper}}_EVENTING_{{entity_singular_upper}}_EVENT_HPP
#include <chrono>
#include <optional>
#include <string>
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid.hpp>
#include <rfl/json.hpp>
#include "ores.eventing.api/domain/entity_event.hpp"
#include "ores.eventing.api/domain/entity_event_traits.hpp"
#include "ores.{{component_include}}/messaging/{{entity_singular}}_protocol.hpp"
#include "ores.utility/rfl/reflectors.hpp" // IWYU pragma: keep.
namespace ores::eventing::domain {
/**
* @brief Event traits for {{entity_title_lower}}'s changes.
*
* The events collection is addressed by three subjects, one per action, so the
* traits state the prefix and the action completes it. The conversion is this
* entity's own because the notification carries the key as a JSON object and
* only this entity knows which columns its key record holds.
*/
template<>
struct entity_event_traits<ores::{{component}}::messaging::{{entity_singular}}_event> {
static constexpr std::string_view subject_prefix = "{{event_prefix}}";
static ores::{{component}}::messaging::{{entity_singular}}_event
from_notification(const entity_event_notification& notification) {
ores::{{component}}::messaging::{{entity_singular}}_event event;
event.event_id = boost::lexical_cast<boost::uuids::uuid>(notification.event_id);
if (const auto key =
rfl::json::read<ores::{{component}}::messaging::{{entity_singular}}_key>(
notification.key))
event.key = *key;
event.action = notification.action;
event.version = notification.version;
event.occurred_at = notification.occurred_at;
event.correlation_id = notification.correlation_id;
return event;
}
};
}
#endif
{{/domain_entity}}
2. See also
- Parent facet: ores.cpp.nats-eventing
- Template variable reference