Skip to content

Using the Serializable Event Message

The AbstractSerializableMessage allows you to quickly create Event Messages that are dispatched.


Event Message Class

First you will need to create your Event Message Class.

use SonsOfPHP\Component\EventSourcing\Message\AbstractSerializableMessage;

class AggregateFieldChangedEventMessage extends AbstractSerializableMessage

Initializing Event Message Class

Once you create you Event Message Class, using it is very easy.

$event = AggregateFieldChangedEventMessage::new()->withPayload([
    'previous_value' => $previousValue,
    'new_value'      => $newValue,