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

v1.0.0 2025-10-28 03:45 UTC

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-foundation which 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\OrderPlacedorder.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 – forwards X-Tenant-ID or 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.