alazziaz/laravel-dapr-listener

Listener utilities for consuming Dapr Pub/Sub messages as Laravel events.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/alazziaz/laravel-dapr-listener

v1.0.1 2025-10-28 19:35 UTC

This package is auto-updated.

Last update: 2025-10-28 21:21:18 UTC


README

Packagist Version Total Downloads

Discover Dapr topics, expose /dapr/subscribe, and handle ingress HTTP calls by re-dispatching Laravel events.

Installation

composer require alazziaz/laravel-dapr-listener

Depends on alazziaz/laravel-dapr-foundation for shared infrastructure.

Subscription discovery

The service provider scans app/Events and app/Listeners for the #[Topic] attribute and registers derived topics with the shared SubscriptionRegistry. Configured overrides in config/dapr-events.php are merged automatically.

Run php artisan dapr-events:list to inspect the discovered routes.

HTTP ingress

Routes are registered under the configurable prefix (default dapr):

  • GET /dapr/subscribe – list of {pubsubname, topic, route} subscriptions.
  • POST /dapr/ingress/{topic?} – wildcard handler invoked by the Dapr sidecar.

Requests may be wrapped in CloudEvents; the listener extracts the payload, hydrates the Laravel event class, and dispatches it through the application event dispatcher. Inbound events are marked so they are not re-published.

Listener middleware

Configured through listener.middleware:

  • RetryOnceMiddleware – retries the pipeline a single time before surfacing the exception (causing Dapr to retry based on component settings).
  • CorrelatedMessageMiddleware – restores correlation IDs from metadata for logging and downstream services.
  • TenantHydratorMiddleware – exposes tenant context via the Laravel context facade.

Artisan tooling

php artisan dapr-events:listener App\\Events\\OrderPlaced scaffolds a listener class in app/Listeners, defaulting to OrderPlacedListener.

The stub integrates cleanly with Laravel's native event system—no special base classes required.

PHP compatibility note

The listener depends on dapr/php-sdk, which currently only offers a dev-main branch targeting PHP 8.4. Projects running on PHP 8.2/8.3 should either loosen Composer’s minimum stability (while keeping prefer-stable: true) or pin the SDK to an earlier tag that supports their PHP version until a stable release is available.