-
Notifications
You must be signed in to change notification settings - Fork 39
Event store
The event store is a key part of Cirqus. It is configured with the Command Processor. The event store is where Cirqus saves and loads events. This means that this is your primary database, and everything else can be (re)created from this data.
Requirements for an event store are modest: It needs to be able to save an event batch (i.e. one or more events) atomically, and it needs to be able to guard two constraints:
- (aggregate root ID, sequence number) for each event is unique
- (global sequence number) for each event is unique.
While these are the most basic requirements, it's more fun to use an event store if it is capable of efficiently retrieving (preferably by streaming them) events
- ordered by global sequence number from a specific global sequence number and on (this is what the views/projections will usually do)
- ordered by sequence number for a specific aggregate root ID and a specific sequence number and on (this is used to hydrate aggregate root instances for command processing and when inspected from views)
which all of the current event store implementations are perfectly capable of doing.
var processor = CommandProcessor.With().EventStore(conf =>
{
conf.UseFiles("/path/to/event/store/location/");
}).Create();
SQLite has the same configuration parameters, all it needs is the path to the database file.
SQL Server, PostgreSQL and MongoDB are all configured in the same way. They have an optional boolean at the end to disable automatic table creation.
var processor = CommandProcessor.With().EventStore(conf =>
{
conf.UseSqlServer("NameOfConnectionStringOrConnectionStringItself", "NameOfTableWhereEventsShouldGo");
}).Create();
Cirqus will create the events table (unless you supply false
as the last parameter), so make sure the database user has the right to create new tables.