andreo/eventsauce-messenger
Symfony Messenger integration for EventSauce. Dispatch and consume EventSauce messages via Messenger handlers, with optional autoconfiguration through the AsEventSauceMessageHandler attribute or manual service tagging. Requires PHP 8.2+ and Symfony Messenger 6.2+.
Laravel + Symfony Messenger Bridge:
spatie/laravel-messenger or custom bridge) acts as the message broker for Laravel, replacing or extending the native Bus system.eventsauce-messenger acting as the adapter between Symfony Messenger and EventSauce’s event consumption.queue:work) must be configured to process Symfony Messenger messages, requiring custom middleware sequencing.Key Compatibility Points:
Message interface (e.g., extends \EventSauce\EventSourcing\Message).#[AsEventSauceMessageHandler] attribute or Symfony Messenger tags (messenger.message_handler).HandleEventSauceMessageMiddleware must be inserted into Laravel’s queue worker pipeline (e.g., via Horizon or custom QueueWorker).Prerequisites:
composer require symfony/messenger andreo/eventsauce-messenger eventsauce/event-sourcing spatie/laravel-messenger
spatie/laravel-messenger to use Symfony Messenger (e.g., config/messenger.php with eventBus).EventSauce Setup:
EventSauce\EventSourcing\Postgres\PostgresEventRepository).app/Events/FooCreated.php) extending EventSauce\EventSourcing\Message.app/Projections/FooProjection) to sync data to Laravel models.Symfony Messenger Integration:
eventBus in config/messenger.php:
'buses': [
'eventBus': [
'middleware': [
'send_message',
'Andreo\EventSauce\Messenger\Middleware\HandleEventSauceMessageMiddleware',
'handle_message',
],
],
],
MessengerMessageDispatcher in Laravel’s AppServiceProvider:
$this->app->bind(
\Andreo\EventSauce\Messenger\Dispatcher\MessengerMessageDispatcher::class,
fn($app) => new \Andreo\EventSauce\Messenger\Dispatcher\MessengerMessageDispatcher(
$app->get('messenger.bus.eventBus')
)
);
Event Handlers:
#[AsEventSauceMessageHandler]:
use Andreo\EventSauce\Messenger\Attribute\AsEventSauceMessageHandler;
use EventSauce\EventSourcing\EventConsumption\EventConsumer;
class FooHandler extends EventConsumer
{
#[AsEventSauceMessageHandler(bus: 'eventBus')]
public function onFooCreated(FooCreated $event): void
{
// Handle event (e.g., update projection)
}
}
config/services.yaml:
services:
App\Handlers\FooHandler:
tags:
- { name: messenger.message_handler, handles: App\Events\FooCreated, bus: eventBus, method: handle }
Dispatching Events:
event(new FooCreated()) with Symfony Messenger:
$this->messenger->dispatch(new FooCreated());
send() method:
$this->messenger->send(new FooCreated());
Queue Worker Configuration:
queue:work to process Symfony Messenger messages:
php artisan queue:work --queue=eventBus --daemon
QueueWorker to include HandleEventSauceMessageMiddleware.Laravel-Symfony Conflicts:
ParameterBag or Laravel’s ExtendServiceProvider.Event facade and Symfony Messenger.HandleEventSauceMessageMiddleware after send_message and before handle_message in Symfony Messenger’s pipeline.EventSauce-Specific:
Message classes are JSON-serializable (compatible with Symfony Messenger’s transport).Model observers or EventSauce projections to sync data (avoid duplicate logic).Laravel Code → Symfony Messenger → EventSauce Dispatcher → EventSauce Event Store → Projections → Laravel Models
[send_message] → [HandleEventSauceMessageMiddleware] → [handle_message]
Illuminate\Bus\QueueWorker).MessageBus integration.HandleEventSauceMessageMiddleware may need bug fixes if Laravel/Symfony versions diverge.monolog for message dispatch logs.queue:failed table to include Symfony Messenger-specific metadata.failed_messages table (if using Doctrine transport).queue:failed for queue worker crashes.BarCreated|BazCreated) may require custom error handling for mismatched events.symfony messenger eventsauce or laravel symfony messenger.queue:work horizontally, but ensure EventSauce projections are idempotent (handle duplicate events).EventConsumer may increase memory usage per event compared to Laravel’s lightweight jobs.doctrine://default) for high-volume event dispatching.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Queue Worker Crash | Events lost if not retried. | Enable Laravel’s failed_jobs table + Symfony Messenger’s retry_strategy. |
| EventSauce Store Unavailable | Events dispatched but not stored. | Use circuit breakers (e.g., Symfony Messenger’s failed_message handling). |
| Projection Failure | Inconsistent read models. | Implement dead-letter queues for failed projections. |
| Symfony Messenger Misconfiguration | Events routed to wrong bus/handler. |
How can I help you explore Laravel packages today?