Skip to content

softonic/laravel-protobuf-events

Repository files navigation

Laravel Protobuf Events

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

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.

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.

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

Publishing messages

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

ExternalEvents::publish(
    (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
);

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.

$ make tests

To open a terminal in the dev environment:

$ make debug

License

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

About

Helper to allow nuwber/rabbitevents to work with protobuf

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5