eventsauce/message-outbox-for-doctrine
doctrine/dbal. This introduces abstraction overhead but ensures database portability (e.g., switching from MySQL to PostgreSQL). For Laravel-centric teams, this may feel over-engineered unless event sourcing is a core requirement.Event system or queue-based outbox (e.g., spatie/laravel-queueable-entity) may offer simpler alternatives.Message, Event) differ from Laravel’s Event system.laravel-queue-outbox or a custom outbox table may suffice.prooph/event-store or spatie/laravel-event-sourcing for Laravel-native solutions.| Risk Area | Severity | Mitigation |
|---|---|---|
| Doctrine DBAL Adoption | High | Isolate Doctrine to only the outbox table; use Laravel DB for everything else. |
| EventSaucePHP Complexity | High | Start with a proof-of-concept (e.g., 1–2 critical events) before full adoption. |
| Transaction Conflicts | Medium | Test nested transaction behavior; use DB::transaction() explicitly. |
| Performance Overhead | Medium | Benchmark insert/select latency for the outbox table under load. |
| Monitoring Gaps | Medium | Implement custom Laravel Observers or Telescope channels for outbox metrics. |
| Vendor Lock-in | Low | EventSaucePHP is MIT-licensed; outbox table schema is portable. |
laravel-queue-outbox or a custom outbox table achieve the same goals with less overhead?| Component | Fit Level | Notes |
|---|---|---|
| Laravel | Medium | Not native to Doctrine; requires doctrine/dbal integration. |
| Doctrine DBAL | High | Core dependency; ensures DB portability but adds complexity. |
| EventSaucePHP | Medium | Adds event-store complexity; may be overkill for simple async use cases. |
| Laravel Queues | Low | If queues suffice, consider spatie/laravel-queueable-entity or a custom outbox table. |
| Event Sourcing | High | Ideal for audit logs, CQRS, or replayable event streams. |
| Database | High | Works with MySQL, PostgreSQL, SQLite (via Doctrine). |
Assessment Phase
Event::dispatch, queues, or direct HTTP calls).OrderCreated, PaymentProcessed).Dependency Setup
composer require doctrine/dbal eventsauce/eventsauce eventsauce/message-outbox-for-doctrine
config/database.php (or a service provider):
'connections' => [
'doctrine' => [
'driver' => 'pdo_mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
// ... other config
],
],
$this->app->bind(\Doctrine\DBAL\Connection::class, function ($app) {
return \Doctrine\DBAL\DriverManager::getConnection($app['config']['database.connections.doctrine']);
});
Outbox Table Migration
Schema::create('message_outbox', function (Blueprint $table) {
$table->id();
$table->string('message_type');
$table->text('message_body');
$table->timestamp('scheduled_at')->useCurrent();
$table->timestamp('processed_at')->nullable();
$table->index(['processed_at']);
});
Event Publishing Integration
Event::dispatch with DoctrineMessageOutbox:
use EventSauce\MessageOutboxForDoctrine\DoctrineMessageOutbox;
use EventSauce\EventSauce;
// In a service/repository:
$connection = $this->app->make(\Doctrine\DBAL\Connection::class);
$outbox = new DoctrineMessageOutbox($connection);
$eventSauce = new EventSauce($messageBus, $eventStore);
// Publish an event
$outbox->publish(
new OrderCreated($orderId, $amount),
new \DateTimeImmutable(),
"order-$orderId",
'Order'
);
DB::transaction(function () use ($outbox, $order) {
// Save order to DB
$order->save();
// Publish event
$outbox->publish(new OrderCreated(...));
});
Consumer Setup
How can I help you explore Laravel packages today?