Looking to hire Laravel developers? Try LaraJobs

laravel-cloudevents maintained by stafftastic

Description
A reusable cloudevent system for laravel projects.
Author
Last update
2024/07/15 12:25 (dev-main)
License
Links
Downloads
13 707

Comments
comments powered by Disqus

Archival notice

This repo is no longer maintained. We wholly recommend just using the Laravel Kafka package and CloudEvents library directly.

Laravel CloudEvents

A Laravel library to publish Illuminate Events to Kafka.

Installation

Install the package:

composer require stafftastic/laravel-cloudevents

Usage

  1. Publish config file
php artisan vendor:publish --provider="stafftastic\LaravelCloudEvents\CloudEventServiceProvider"
  1. Create your applications context:
<?php

namespace App\Events;

use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use stafftastic\CloudEvents\CloudEventable;
use stafftastic\CloudEvents\IsCloudEvent;

class UserCreated implements CloudEventable
{
    use Dispatchable;
    use InteractsWithSockets;
    use SerializesModels;
    use IsCloudEvent;

    /**
     * Create a new event instance.
     *
     * @param  \Domain\Users\Models\User  $user
     *
     * @return void
     */
    public function __construct(public User $user)
    {
    }

    public function getCloudEventType(): string
    {
        return 'com.stafftastic.users.created';
    }

    public function getCloudEventTopic(): string
    {
        return 'stafftastic';
    }

    public function toCloudEventData(): array
    {
        return [
            'user' => $this->user,
        ];
    }
}