event-engine/prooph-v7-event-store
Prooph v7 event store bindings for Event Engine. Includes a Prooph-compatible FilesystemEventStore for demos/workshops plus in-memory projecting support via InMemoryProjectionManager. Use it to create streams, append events, and run simple projections.
Installation
composer require event-engine/prooph-v7-event-store
Ensure prooph/event-store (v7+) is also installed as a dependency.
Basic Configuration
Add the service provider to config/app.php:
EventEngine\ProophEventStore\ProophEventStoreServiceProvider::class,
Publish the config (if needed):
php artisan vendor:publish --provider="EventEngine\ProophEventStore\ProophEventStoreServiceProvider"
First Use Case: Persisting an Event
use EventEngine\ProophEventStore\EventStore;
use Prooph\EventStore\Domain\Message;
$eventStore = app(EventStore::class);
$event = new MyDomainEvent('payload', ['metadata']);
$eventStore->dispatch($event); // Persists to Prooph Event Store
Where to Look First
config/event-engine-prooph-event-store.php (if published).EventEngine\ProophEventStore\Facades\EventStore for quick access.EventEngine\ProophEventStore\Contracts\EventStore for custom implementations.Event Dispatching
Use EventStore::dispatch() for synchronous persistence:
$eventStore->dispatch(new UserRegistered('user@example.com'));
For async dispatching, integrate with Laravel queues:
$eventStore->dispatchAsync(new OrderPlaced($orderId));
Event Retrieval Fetch events by aggregate ID:
$events = $eventStore->loadAggregate('user-123');
Or stream events from a point in time:
$streamName = 'user-123';
$events = $eventStore->stream($streamName)->getEvents();
Event Subscribing Subscribe to events in real-time:
$eventStore->subscribeTo('user-123', function ($event) {
// Handle event (e.g., update cache, send notification)
});
Integration with Laravel Services
handle():
public function handle()
{
$eventStore->dispatch(new Event('data'));
}
dispatchSync() or dispatchAsync() in job execution.Event::listen('prooph.event_store.event_published', function ($event) {
// Cross-cutting logic
});
Aggregate Root Management Rebuild aggregates from events:
$aggregate = $eventStore->replayAggregate(
UserAggregate::class,
'user-123',
$events
);
EventStore to handle schema migrations.EventStore::replay() to reconstruct state.Stream Naming Collisions
user-123) to isolate aggregates.user-123-events).Async Dispatch Deadlocks
retryAfter.Event Serialization Issues
JsonSerializable or Arrayable.Prooph\EventStore\Serialization\Serializer for complex payloads.Transaction Boundaries
EventStore is not a database transaction manager.DB::transaction(function () use ($eventStore, $event) {
$eventStore->dispatch($event);
// Other DB operations
});
Memory Leaks with Subscribers
EventStore::unsubscribe() or limit subscriber scope.'logging' => [
'enabled' => true,
'channel' => 'single',
],
php artisan prooph:event-store:list-streams
EventStore::replay() to debug state transitions.Custom Serializers Override the default serializer:
$eventStore->setSerializer(new CustomSerializer());
Event Filters Filter events before dispatching:
$eventStore->setEventFilter(function ($event) {
return $event instanceof AllowedEvent;
});
Event Store Plugins
Extend Prooph’s EventStore with plugins (e.g., audit logging):
$eventStore->addPlugin(new AuditPlugin());
Laravel Integration Bind custom Prooph repositories:
$this->app->bind(
Prooph\EventStore\Repository::class,
function () {
return new CustomRepository($eventStore);
}
);
StreamNameFromAggregateId.
Override in config:
'stream_name_strategy' => EventEngine\ProophEventStore\StreamNameFromAggregateType::class,
queue driver in .env:
QUEUE_CONNECTION=database
How can I help you explore Laravel packages today?