neos / contentrepository-development-collection

Work in Progress on the Event Sourced Content Repository as installable set of packages
4 stars 9 forks source link

Concept: Hooking into the command/event flow // Extensibility #100

Open skurfuerst opened 5 years ago

skurfuerst commented 5 years ago

Concept for hooking into the Command / Event Flow

(Discussion @bwaidelich, @kitsunet , @skurfuerst )

Use Cases

Proposal

Implications

We see the Neos UI in the example below as separate application

e.g. for the Neos UI to remember to which document a deleted node belongs, the Neos UI would hook into the following Commands:

On DeleteNode, it will read the projection and remember the parent document node. Remembering in this case can mean directly storing it in the database; or working as a separate event-sourced application (with optionally a separate event store as well).

On PublishNode, we will copy the "Deleted Node" lines from our custom storage table, to the target ContentStream (if the target is not the live WS).

This leaves us with a small inconsistency window, as the separate application has different consistency guarantees. However, for our cases this is very very likely not a problem.

Alternatives (not suggested)

bwaidelich commented 5 years ago

Related to: https://github.com/neos/Neos.EventSourcing/issues/118

bwaidelich commented 5 years ago

After letting the proposal sink in for a few days it still feels a little awkward to access a "foreign" (as in: different Bounded Context) Read Model from the Write Side. But it might be a very pragmatic solution that just works out in practice – we'll have to give it a try. I'll introduce an external Command Bus (league/tactician) to the CR to see if this works.

Nevertheless I want to add some more potential alternatives for the record:


¹ It's probably not feasible to have an actual Aggregate that reconstitutes itself in memory – instead it could always materialize it's state in some database as soon as new events come in

bwaidelich commented 5 years ago

See first draft: https://github.com/neos/contentrepository-development-collection/pull/104 (I moved the longer comment to the PR)

bwaidelich commented 2 years ago

After our last ESCR talk I think that we need something other than a (global) Command Bus. Instead it should (IMO) be an instance of the "Content Repository" that will act as single authority for...

Dispatching Commands

In that sense it is a Command Bus, but not a global one. That way we could handle commands for different CR instances "at the same time". Besides, the API will be easier to use because the correct CommandHandler instance does not need to be known and it could be a single public method, like:

$neosCR->handle(new CreateNodeVariant(...));

Interacting with Core Read Models

It is to be defined, what the "Core Read Models" are, but I think it should be the Content(Sub)Graph and some kind of Diff between two content streams (that also considers deleted nodes)

Registering extensions

We need something more specific than (global) event listeners. Instead I could think of two kinds of extensions:

  1. low level: A special CR listener that will receive all events of a given CR event store
  2. high level: A callback that is invoked whenever the ContentGraph of a given CR is updated (this will allow for interaction with the just-updated graph, e.g. for hierarchical queries)

Some more thoughts