ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
postgres_event_source Class Referencefinal

Event source that bridges PostgreSQL LISTEN/NOTIFY to the event bus. More...

#include <postgres_event_source.hpp>

Collaboration diagram for postgres_event_source:
Collaboration graph

Public Member Functions

 postgres_event_source (database::context ctx, event_bus &bus)
 Constructs a postgres_event_source.
 
 postgres_event_source (const postgres_event_source &)=delete
 
postgres_event_sourceoperator= (const postgres_event_source &)=delete
 
template<typename Event >
void register_mapping (const std::string &entity_name, const std::string &channel_name)
 Register a mapping from entity name to typed domain event.
 
void start ()
 Start the event source.
 
void stop ()
 Stop the event source.
 

Detailed Description

Event source that bridges PostgreSQL LISTEN/NOTIFY to the event bus.

This class wraps postgres_listener_service and translates low-level entity_change_event notifications into typed domain events that are published to the event bus.

Components can register their entity-to-event mappings via register_mapping(), enabling the event source to automatically publish the correct typed event when a database notification is received.

Usage:

postgres_event_source source(ctx, bus);
// Register entity mappings
source.register_mapping<currency_changed_event>("ores.risk.currency",
"ores_currencies");
source.start();
A typed, thread-safe, in-process publish/subscribe event bus.
Definition event_bus.hpp:119
Event source that bridges PostgreSQL LISTEN/NOTIFY to the event bus.
Definition postgres_event_source.hpp:57

Constructor & Destructor Documentation

◆ postgres_event_source()

Constructs a postgres_event_source.

Parameters
ctxDatabase context for the listener connection.
busReference to the event bus for publishing events.

Member Function Documentation

◆ register_mapping()

template<typename Event >
void register_mapping ( const std::string &  entity_name,
const std::string &  channel_name 
)

Register a mapping from entity name to typed domain event.

When a notification is received for the specified entity, the event source will publish an instance of Event to the bus with the notification's timestamp.

Template Parameters
EventThe domain event type to publish (must have a timestamp member).
Parameters
entity_nameThe fully qualified entity name (e.g., "ores.risk.currency").
channel_nameThe PostgreSQL channel to listen on (e.g., "ores_currencies").
Here is the caller graph for this function:

◆ start()

void start ( )

Start the event source.

Begins listening for PostgreSQL notifications on all registered channels.

◆ stop()

void stop ( )

Stop the event source.

Stops listening for notifications.