Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

stafftastic/laravel-cloudevents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0efecb4 · Jul 15, 2024

History

34 Commits
May 12, 2022
Aug 26, 2022
Aug 30, 2022
Mar 23, 2023
Mar 23, 2023
Sep 6, 2022
Jul 15, 2024
Mar 23, 2023
Mar 23, 2023
Mar 23, 2023
Mar 23, 2023
May 12, 2022

Repository files navigation

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,
        ];
    }
}