sulu/messenger
Symfony Messenger add-on for Sulu providing stamps and middlewares to configure the Sulu message bus. Includes UnpackExceptionMiddleware to surface real handler errors and LockMiddleware to prevent concurrent access. Usable standalone in any Symfony app.
spatie/laravel-messenger or direct symfony/messenger adoption. Its middleware architecture is highly compatible with Laravel’s event/queue systems, enabling:
queue:work for background processing (though custom transport adapters may be needed).DoctrineFlushMiddleware targets Doctrine, a custom middleware could bridge to Eloquent’s flush() or save() methods.UnpackExceptionMiddleware enables clean HTTP status codes (e.g., 422 Unprocessable Entity) for failed jobs, improving API consistency.DoctrineFlushMiddleware (Laravel’s Eloquent would require custom work).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Symfony Dependency | Laravel’s ecosystem is PHP-first but not Symfony-first. Integrating symfony/messenger may introduce versioning conflicts or require abstraction layers. |
Use spatie/laravel-messenger as a bridge or wrap Symfony components in Laravel services. Test with symfony/messenger:^6.4 and Laravel 10+ for compatibility. |
| Doctrine Lock-In | DoctrineFlushMiddleware and LockMiddleware assume Doctrine. Laravel’s Eloquent lacks native support, requiring custom adapters (e.g., symfony/lock for file/database locks). |
Build a Laravel-specific lock service using symfony/lock with file/database backends. For flushing, wrap Eloquent’s flush() in a middleware or use Laravel’s queue:after hooks. |
| Error Handling | UnpackExceptionMiddleware targets Symfony’s HandlerFailedException. Laravel’s queue jobs throw native exceptions (e.g., Throwable). |
Extend the middleware to handle Laravel’s ShouldQueue exceptions or use a decorator pattern to translate exceptions. |
| Performance Overhead | Middlewares add latency. LockMiddleware and DoctrineFlushMiddleware may block jobs if misconfigured (e.g., long lock TTLs or unnecessary flushes). |
Profile with real-world payloads (e.g., 1000 RPS). Use short lock TTLs (e.g., 5–30s) and selective flushing (e.g., only for critical entities). |
| Transport Gaps | Laravel’s queue drivers (Redis, database, etc.) may not align with Symfony’s transports (AMQP, Doctrine, etc.). | Use spatie/laravel-messenger’s Symfony transport adapters or build custom bridges (e.g., map Laravel’s queue:work to Symfony’s BusInterface). |
| Testing Complexity | Middleware interactions (e.g., lock + flush) require complex test setups (e.g., mocking Doctrine, locks, and transports). | Adopt Symfony’s Messenger test utilities (e.g., TestBus) and Laravel’s Queue::fake() for isolated testing. Use Dockerized environments for integration tests with locks/Doctrine. |
Symfony Adoption:
symfony/messenger) or does this require full Symfony adoption (e.g., for LockMiddleware)?Database Strategy:
DoctrineFlushMiddleware, will we migrate to Doctrine or build a custom Eloquent adapter? What’s the effort/risk of the latter?symfony/lock), database (e.g., optimistic_lock column), or Redis.Error Handling:
UnpackExceptionMiddleware override Laravel’s default job failure behavior (e.g., failed_jobs table) or complement it?422, 500), and how will this integrate with Laravel’s App\Exceptions\Handler?Concurrency Model:
LockMiddleware’s TTLs need tuning (e.g., 5s vs. 30s)?Migration Path:
UnpackExceptionMiddleware for error handling) or big-bang migrate to full message-driven architecture?Observability:
Bus events, Laravel’s queue:failed logging, or custom metrics (e.g., Prometheus).Queue::after() hooks?Vendor Lock-In:
symfony/messenger-bundle for idempotency, php-amqplib for advanced AMQP) that could reduce dependency risk?spatie/laravel-messenger or direct symfony/messenger).sulu/messenger adding domain-specific middlewares.DoctrineFlushMiddleware (Laravel’s Eloquent would require a custom bridge).symfony/lock supports file, database, or Redis. For Laravel, Redis or database locks (e.g., optimistic_lock column) are recommended.spatie/laravel-messenger’s Symfony transport adapters or custom bridges (e.g., map Laravel’s queue:work to Symfony’s BusInterface).spatie/laravel-messenger supports them or build adapters.symfony/messenger-bundle: More feature-rich (e.g., idempotency, retry) but heavier.league/amqp: For pure AMQP use cases without Symfony.| Phase | Action | Tools/Libraries | Risks |
|---|---|---|---|
| Assessment | Audit existing synchronous workflows (e.g., controllers, cron jobs) to identify candidates for async processing. Prioritize high-failure or long-running tasks. | Laravel Debugbar, Xdebug, Queue monitoring | Underestimating migration effort. |
| Symfony On-Ramp | Integrate symfony/messenger via spatie/laravel-messenger. Start with basic message handling (no middlewares) to validate the bus. |
spatie/laravel-messenger, symfony/messenger:^6.4 |
Version conflicts, transport misconfigurations. |
| Middleware Rollout | Add middlewares incrementally: |
UnpackExceptionMiddleware for error handling (low risk).How can I help you explore Laravel packages today?