Passive Projections
Mark a projection as passive (not actively observing) using [Passive]:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;using Cratis.Chronicle.ReadModels;
[EventType]public record MbPassiveSnapshotCreated(string Data);
[Passive]public record MbPassiveHistoricalSnapshot( [Key] Guid Id,
[SetFrom<MbPassiveSnapshotCreated>(nameof(MbPassiveSnapshotCreated.Data))] string Data);Kotlin does not support this workflow yet.Java does not support this workflow yet.defmodule MyApp.Events.PassiveSnapshotCreated do use Chronicle.Events.EventType, id: "passive-snapshot-created-v1"
defstruct [:data]end
defmodule MyApp.ReadModels.PassiveHistoricalSnapshot do use Chronicle.ReadModels.ReadModel, passive: true
alias MyApp.Events.PassiveSnapshotCreated
defstruct [:id, :data]
from PassiveSnapshotCreated, set: [id: :event_source_id, data: :data]endimport { eventType, Guid, passive, readModel, setFrom } from '@cratis/chronicle';
@eventType()class MbPassiveSnapshotCreated { data = '';}
@readModel()@passiveclass MbPassiveHistoricalSnapshot { id: Guid = Guid.empty;
@setFrom(MbPassiveSnapshotCreated, 'data') data = '';}When to use
Section titled “When to use”- On-demand projections that are only rebuilt when explicitly requested
- Historical snapshots
- Resource-intensive projections that shouldn’t run continuously
Best practices
Section titled “Best practices”- Use for expensive projections that are only needed occasionally
- Consider the trade-off between resource usage and data freshness
- Ensure you have mechanisms to trigger rebuilds when needed