If the dispatched command
is an instance of Prooph\Common\Messaging\Message
the transaction manager will also add causation metadata
to each recorded event during the transaction.
Two entries are added to the metadata:
causation_id
=$command->uuid()->toString()
causation_name
=$command->messageName()
.
The CausationMetadataEnricher
is a dual plugin, it's a plugin for event-store as well as for the message-bus.
$causationMetadataEnricher = new CausationMetadataEnricher();
$causationMetadataEnricher->attachToEventStore($eventStore);
$causationMetadataEnricher->attachToMessageBus($commandBus);
That's it!
If you are using the container-aware factories
shipped with prooph/event-store and prooph/service-bus you may also
want to auto register the CausationMetadataEnricher
.
Add the CausationMetadataEnricher
as plugin to the command bus as well as the event-store.
Keep in mind, that this service must be shared in order to work (which it is by default in most container implementations).