eventually-rs icon indicating copy to clipboard operation
eventually-rs copied to clipboard

Minimal example?

Open d4h0 opened this issue 3 years ago • 3 comments

Hi,

I just discovered eventually via the Reddit post today, and because I have never seen event sourcing in action I looked for an example. There is the example app, however, I think a more minimal one-file example would be useful for people who are interested in a quick overview.

Would that be possible, or is event sourcing too complex for a simple example like that?

d4h0 avatar Oct 04 '20 22:10 d4h0

++ Also how this library can be used with some database backend, for example, if I want to store all my events in PostgreSQL? In the current example, repository is in memory.

UPD: I think, a tutorial how to develop such app would be useful.

AngelicosPhosphoros avatar Oct 05 '20 01:10 AngelicosPhosphoros

Hi @d4h0 and @AngelicosPhosphoros :wave:

Thank you for posting the issue!

@d4h0: it might be possible to put everything in a single file, however that file might be a tad long :sweat_smile: I'll try to make an easier example to follow. However, let me guide you through the current one.

As a good starting point, you can follow the aggregate module documentation, where you can see a minimal example of how to set up an Aggregate.

This is the main part of Event Sourcing from a user perspective, frankly.

Everything else is just wiring up the EventStore to the Repository and write the handlers that call the Repository and emits commands.

In eventually-app-example:

  1. This is where you'll find the domain implementation, namely the OrderAggregate
  2. This is where you call the Repository to get an AggregateRoot to submit commands (just an example of one single HTTP handler, there are more, one per each command)
  3. This is how you initialize EventStore and Repository in the run, then you can pass these objects to the State of your App (if you're using Tide) so that they are accessible in the HTTP handlers (point 2.)

@AngelicosPhosphoros: indeed, the current example uses an inmemory EventStore.

I thought I included an example for setting up the Postgres' EventStore, but I'm afraid I forgot it.

You can find it in the crate documentation for eventually_postgres

I will include the documentation in the next patch release :+1:

ar3s3ru avatar Oct 05 '20 07:10 ar3s3ru

Links are stale for this.

wyhinton avatar Jun 27 '21 00:06 wyhinton