Message Outbox- Usage
Published at 02 May 2021
The outbox module consists of three parts, a repository, a dispatcher
and a relay. The repository is responsible storing and retrieving
messages. The dispatcher is responsible for putting messages
in the repository and hooks into the core by implementing the
The relay is responsible for fetching messages from the repository and committing them (mark as consumed or delete).
Once you’ve setup your outbox repository, you’re ready to use the outbox.
The outbox package provides a
that forwards the messages to the outbox repository.
use EventSauce\EventSourcing\Message; use EventSauce\MessageOutbox\OutboxMessageDispatcher; $messageDispatcher = new OutboxMessageDispatcher($yourRepository); $messageDispatcher->dispatch(new Message(new YourEvent(1234)));
use EventSauce\MessageOutbox\OutboxRelay; $relay = new OutboxRelay( $yourRepository, $forwardingMessageConsumer, $backOffStrategy, /* optional */ $commitStrategy, /* optional */ );
A back-off strategy may be specified. By default an exponential back-off strategy is used. For more information about the available strategies and configuration options, view the readme.
Messages can be committed using two strategies:
- Mark message as consumed
- Delete the message
$markAsConsumed = new EventSauce\MessageOutbox\MarkMessagesConsumedOnCommit(); $deleteMessage = new EventSauce\MessageOutbox\DeleteMessageOnCommit();