alazziaz / laravel-dapr-publisher
Publisher helpers for sending Laravel events over Dapr Pub/Sub.
Installs: 0
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/alazziaz/laravel-dapr-publisher
Requires
- php: ^8.2
- alazziaz/laravel-dapr-foundation: ^1.0
- dapr/php-sdk: dev-main
- illuminate/contracts: ^10.0|^11.0|^12.0
- illuminate/events: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- phpstan/phpstan: ^1.11
This package is not auto-updated.
Last update: 2025-10-28 16:49:33 UTC
README
Helper classes and middleware pipeline for publishing Laravel events through the Dapr sidecar.
Installation
composer require alazziaz/laravel-dapr-publisher
Requires
alazziaz/laravel-dapr-foundationwhich provides shared config and topic resolution.
EventPublisher
$publisher = app(\AlazziAz\DaprEventsPublisher\EventPublisher::class); $publisher->publish(new App\Events\OrderPlaced($id, $amount));
Publishing behaviour:
- Resolves the topic via
TopicResolver(App\Events\OrderPlaced→order.placed). - Serializes the event payload (array, JsonSerializable,
ProvidesPayload, or property map). - Wraps the payload in a CloudEvent envelope (
serialization.wrap_cloudevent). - Sends the result via
DaprClient::publishEvent.
Middleware pipeline
Configure middleware in config/dapr-events.php under publisher.middleware:
AddCorrelationId– propagates/creates a correlation ID and logs it.AddTenantContext– forwardsX-Tenant-IDor the authenticated user's tenant identifier.AddTimestamp– stamps the publish time in RFC3339 format.
You can push additional middleware classes to mutate metadata or payloads before the publish call.
Testing
Use the fake to assert publishing:
$fake = \AlazziAz\DaprEventsPublisher\Testing\DaprEventFake::register(app()); event(new App\Events\OrderPlaced('123', 9900)); $fake->assertPublished(App\Events\OrderPlaced::class);
See tests/EventPublisherTest.php for more examples.