承接 softonic/laravel-protobuf-events 相关项目开发

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

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

softonic/laravel-protobuf-events

Composer 安装命令:

composer require softonic/laravel-protobuf-events

包简介

Helper to allow nuwber/rabbitevents to work with protobuf

README 文档

README

Latest Version Software License Build Status Total Downloads Average time to resolve an issue Percentage of issues still open

Helper to allow nuwber/rabbitevents to work with protobuf

Requirements

  • PHP >= 8.5
  • Laravel 12.x

Main features

  • Allow to publish/listen protobuf messages using nuwber/rabbit-events easily.

Installation

You can require the last version of the package using composer

composer require softonic/laravel-protobuf-events

Configuration

First you need to configure the nuwber/rabbit-events package to be able to use the package.

Then you must configure config/protobuf-events.php to set the client of the library. This client allows to isolate different services, identifying the origin of the message.

Configuring a listener

In the RabbitEventsServiceProvider::boot() register the listeners that you want using the ExternalEvents::decorateListener() method.

    /**
     * Register any events for your application.
     */
    public function boot(): void
    {
        $this->listen = [
            'my.routing.key' => [
                ExternalEvents::decorateListener(MyListener::class),
            ],
        ];

        parent::boot();
    }

The listener needs a method called handle() that will receive the message and the routing key, and a method called setClient() to identify the origin of the message.

class MyListener
{
    public function setClient(string $client): void
    {
        // ...
    }
    public function handle(ProtobufExampleMessage $event): void
    {
        // ...
    }
}

Publishing messages

To publish a message, you need to use the ExternalEvents::publish() method.

ExternalEvents::publish(
    ':service:',
    (new ProtobufExampleMessage)
        ->setName('My name')
        ->setAge(10)
);

Advanced usage

Sometimes you need to use the package in a different way than the default. For example, you can use the package to decode a message from a string. In that case, you are able to decode the message using the ExternalEvents::decode() method.

$message = ExternalEvents::decode(
    ProtobufExampleMessage::class,
    '\n My name\n 10\n' // The message is a string with the protobuf message.
);

Logging protobuf messages

If you want to log the outgoing protobuf messages and the incoming ones, you can configure a logger and a formatter for the message to be logged. For that purpose you have the methods ExternalEvents::setLogger() and ExternalEvents::setFormatter(). The logger must implement the Psr\Log\LoggerInterface and the formatter, the LogMessageFormatterInterface interface.

ExternalEvents::setLogger(Log:getFacadeRoot());
ExternalEvents::setFormatter(new ProtobufLogMessageFormatter());

The formatter will have two methods, formatOutgoingMessage() and formatIncomingMessage(), that will be called when a message is sent or received, respectively. Both should return a LogMessage object, which contains the message to log and the context.

The log level can be changed by setting the communications_log_level key in config/protobuf-events.php.

Testing

softonic/laravel-protobuf-events has a PHPUnit test suite, and a coding style compliance test suite using PHP CS Fixer.

To run the tests, run the following command from the project folder.

docker compose run --rm test

To run PHPUnit only:

docker compose run --rm phpunit

To check code style:

docker compose run --rm php composer run checkstyle

To fix code style issues:

docker compose run --rm fixcs

To run static analysis:

docker compose run --rm phpstan

To open a terminal in the dev environment:

docker compose run --rm php sh

License

The Apache 2.0 license. Please see LICENSE for more information.

softonic/laravel-protobuf-events 适用场景与选型建议

softonic/laravel-protobuf-events 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.42k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 softonic/laravel-protobuf-events 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 softonic/laravel-protobuf-events 我们能提供哪些服务?
定制开发 / 二次开发

基于 softonic/laravel-protobuf-events 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-12-10