pub struct PgIdIndexer<E: Event + Clone> { /* private fields */ }Expand description
The PgIdIndexer is a helper to index existing fields that have been newly tagged with the #[id] attribute in events.
§Overview
The PgIdIndexer is an EventListener responsible for indexing fields in the event store
that are tagged with the #[id] attribute. This allows querying of old events based
on this new domain identifier once the indexing is complete. The PgIdIndexer listens to events and updates the
event table in the database with the appropriate values.
§Workflow
After you have tagged an existing field in your event structure with the #[id] attribute to mark it
as a domain identifier:
use disintegrate_macros::Event;
use serde::{Serialize, Deserialize};
#[derive(Event, Clone, Serialize, Deserialize)]
struct MyEvent {
#[id]
existing_id: String,
other_field: String,
}-
Register the
PgIdIndexeras anEventListener: Integrate the indexer with the event listener system to process the newly tagged domain identifier:use disintegrate_postgres::PgIdIndexer; use disintegrate_postgres::PgEventListenerConfig; use disintegrate_postgres::PgEventListener; use disintegrate_postgres::PgEventStore; use std::time::Duration; use disintegrate_macros::Event; use disintegrate::serde::json::Json; use serde::{Serialize, Deserialize}; use sqlx::PgPool; #[derive(Event, Clone, Serialize, Deserialize)] struct MyEvent { #[id] existing_id: String, other_field: String, } async fn setup_listener(pool: PgPool, event_store: PgEventStore<MyEvent, Json<MyEvent>>) { let id_indexer = PgIdIndexer::<MyEvent>::new("index_exsting_id", pool); PgEventListener::builder(event_store) .register_listener( id_indexer, PgEventListenerConfig::poller(Duration::from_secs(5)).with_notifier() ) .start_with_shutdown(shutdown()) .await .expect("start event listener failed"); } async fn shutdown() { tokio::signal::ctrl_c().await.expect("ctrl_c signal failed"); } -
Deploy the application: Start the application with the updated event structure and the
PgIdIndexerintegration. Newly created events with the new domain identifier will automatically have the identifier indexed.
Once the indexing process is complete, you can query the event store using the new domain identifier to fetch events.
If indexing is done, you can remove the PgIdIndexer from the list of registered event listeners.
Implementations§
Source§impl<E: Event + Clone> PgIdIndexer<E>
impl<E: Event + Clone> PgIdIndexer<E>
Trait Implementations§
Source§impl<E: Event + Clone + Send + Sync> EventListener<i64, E> for PgIdIndexer<E>
impl<E: Event + Clone + Send + Sync> EventListener<i64, E> for PgIdIndexer<E>
Auto Trait Implementations§
impl<E> Freeze for PgIdIndexer<E>
impl<E> !RefUnwindSafe for PgIdIndexer<E>
impl<E> Send for PgIdIndexer<E>where
E: Send,
impl<E> Sync for PgIdIndexer<E>where
E: Sync,
impl<E> Unpin for PgIdIndexer<E>where
E: Unpin,
impl<E> !UnwindSafe for PgIdIndexer<E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more