symfony/remote-event
Symfony RemoteEvent helps your app receive, validate, and handle remote events (like webhooks) in a consistent way. It provides tooling to parse payloads, verify signatures, map to event objects, and process them through Symfony’s event/HTTP workflows.
Event-Driven Architecture (EDA) Alignment: The package is a perfect fit for Laravel applications transitioning to or adopting event-driven patterns, particularly for cross-service communication (e.g., microservices, webhooks, or async workflows). It abstracts away transport-specific details (HTTP, AMQP, etc.), allowing Laravel to consume remote events as first-class citizens alongside its native events. This aligns with Laravel’s queue system (Horizon) and event system, enabling seamless integration without reinventing event buses or validation logic.
Symfony-Laravel Synergy:
While Symfony’s Messenger component is the backbone, Laravel’s existing stack (e.g., Illuminate\Queue, Illuminate\Validation, Illuminate\Http\Client) can be leveraged with minimal overhead. Key compatibility points:
HttpClient alongside Laravel’s HttpClient or Guzzle via a transport adapter pattern.Validator can integrate with Laravel’s Validator facade or libraries like spatie/laravel-validation.Illuminate\Pipeline) for event routing, logging, or transformation.ContainerInterface behind a Laravel service provider or decorator pattern to avoid tight coupling.Key Use Cases for Laravel:
OrderCreated → InventoryService).Core Features and Laravel Compatibility:
| Feature | Laravel Integration Path | Complexity |
|---|---|---|
| Event Serialization | Use Laravel’s json_encode/json_decode or Symfony’s Serializer via a service wrapper. |
Low |
| HTTP Transport | Leverage Laravel’s HttpClient or wrap Symfony’s HttpClient behind an adapter. |
Medium |
| AMQP Transport | Use Laravel’s pestle or php-amqplib with a Symfony Messenger transport adapter. |
High |
| Validation | Extend Laravel’s Validator or use Symfony’s Validator via a facade/service. |
Low |
| Middleware | Adapt PSR-15 middleware to Laravel’s Pipeline or Kernel. |
Medium |
| Retry Logic | Integrate with Laravel’s Queue retries or Symfony’s RetryExtension. |
Low |
Critical Integration Points:
Event class lacks RemoteEventInterface. A wrapper class (e.g., LaravelRemoteEvent) can bridge the gap:
class LaravelRemoteEvent implements RemoteEventInterface {
public function __construct(private RemoteEvent $event) {}
public function dispatch() {
event(new LaravelEvent($this->event->toArray()));
}
}
ContainerInterface requires a Laravel service provider to resolve dependencies. Example:
class RemoteEventServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(RemoteEventInterface::class, function ($app) {
return new RemoteEvent($app->make(SymfonyContainerAdapter::class));
});
}
}
RemoteEventTransport) and implement adapters for:
HttpClient → Laravel’s HttpClient.pestle) → Symfony’s AmqpExtTransport.| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Dependency Complexity | Symfony’s Container, Messenger, and HttpClient add ~5MB to Laravel’s footprint. |
Use Composer’s replace to avoid bundling full Symfony components. Abstract dependencies behind interfaces (e.g., TransportInterface, ValidatorInterface) to swap implementations later. |
| Learning Curve | Team unfamiliar with Symfony’s Messenger or PSR-15 middleware. | Provide internal documentation with Laravel-specific examples (e.g., "How to create a Laravel-compatible middleware"). Start with a PoC for a single event type (e.g., Stripe webhooks). |
| Async Handling | Remote events may block HTTP requests if not dispatched to queues. | Enforce async dispatching by default: wrap RemoteEvent handlers in Laravel jobs (e.g., HandleRemoteEventJob). Use Symfony’s AsyncTransport for background processing. |
| Validation Overhead | Custom validation rules may not align with Laravel’s Validator. |
Use Symfony’s Validator as a service alongside Laravel’s validator. Create a hybrid validation pipeline (e.g., Laravel for simple rules, Symfony for complex schemas). |
| Transport Limitations | Laravel’s native HTTP client may not support all Symfony Messenger features (e.g., retries). | Build a custom transport adapter that bridges Symfony’s HttpClient with Laravel’s HttpClient, exposing only needed features (e.g., retries, middleware). |
| Event Versioning | Lack of built-in schema evolution for remote events. | Implement a custom event versioning strategy using Laravel’s eloquent events or a separate schema registry (e.g., JSON Schema stored in the database). |
| Testing Complexity | Mocking Symfony’s Container or Messenger in Laravel tests. |
Use Laravel’s Mockery to mock dependencies. Create a test double for RemoteEvent that bypasses Symfony’s container (e.g., FakeRemoteEvent). |
| Performance Impact | Symfony’s Messenger may introduce overhead for high-throughput events. | Benchmark throughput vs. Laravel’s native queue system. Optimize by using Laravel’s queue workers for transport and Symfony’s Messenger only for validation/middleware. |
Architecture:
Team Readiness:
Use Case Scope:
Operational Impact:
Horizon or build custom metrics.AsyncTransport or Laravel’s queue workers.Long-Term Vision:
HttpClient or Guzzle as the transport, wrapped in a Symfony Messenger adapter.Validator with Symfony’s Validator for a hybrid approach.RemoteEvent to Laravel’s Event systemHow can I help you explore Laravel packages today?