承接 jozi/laravel-rabbitevents-sourcing 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jozi/laravel-rabbitevents-sourcing

Composer 安装命令:

composer require jozi/laravel-rabbitevents-sourcing

包简介

Integration between nuwber/rabbitevents and spatie/laravel-event-sourcing packages

README 文档

README

A simple integration between nuwber/rabbitevents and spatie/laravel-event-sourcing. Both are used to facilitate event sourcing and intraservice communication using RabbitMQ topic exchanges.

Installation

Using composer:

composer require jozi/laravel-rabbitevents-sourcing

Usage/Examples

All stored and published events extends the StoredRabbitEvent class. These events will be handled for both event sourcing (spatie/laravel-event-sourcing) and publishing to RabbitMQ (nuwber/rabbitevents).

For this class, a string $eventKey is explictly required for the event to be published. The $eventKey is the same as RabbitMQ's routing key.

use Jozi\Events\StoredRabbitEvent;

class AccountCreated extends StoredRabbitEvent
{
    public $eventKey = 'account.created';

    /** @var array */
    public $accountAttributes;

    public function __construct(array $accountAttributes)
    {
        $this->accountAttributes = $accountAttributes;
    }

    public function toPublish(): array
    {
        return $this->accountAttributes;
    }
}

After an event has been defined, you may invoke it using the publish_event helper function. It is just a simple wrapper for invoking both event and publish as a one-liner.

class Account extends Model
{
    protected $guarded = [];

    public static function createWithAttributes(array $attributes): Account
    {
        /*
         * Let's generate a uuid.
         */
        $attributes['uuid'] = (string) Uuid::uuid4();

        /*
         * The account will be created inside this event using the generated uuid.
         */
        publish_event(new AccountCreated($attributes));

        /*
         * The uuid will be used the retrieve the created account.
         */
        return static::getByUuid($attributes['uuid']);
    }
}

Acknowledgements

License

MIT

统计信息

  • 总下载量: 56
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固