Download the PHP package rabbitevents/publisher without Composer
On this page you can find all versions of the php package rabbitevents/publisher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rabbitevents/publisher
More information about rabbitevents/publisher
Files in rabbitevents/publisher
Package publisher
Short Description The Publisher component of the RabbitEvents package.
License MIT
Informations about the package publisher
RabbitEvents Publisher
The RabbitEvents Publisher component provides an API for publishing events across the application structure. More information is available in the Nuwber's RabbitEvents documentation.
The RabbitEvents Publisher is the part that informs all other microservices that a payment has succeeded.
Table of Contents
- Installation via Composer
- Configuration
- Publishing
- Testing
Installation via Composer
RabbitEvents Publisher can be installed via the Composer package manager:
After installing Publisher, you can execute the rabbitevents:install Artisan command, which will install the RabbitEvents configuration file into your application:
Configuration
Details about the configuration are described in the library documentation.
Publishing
Using an Event class
Here is an example event class:
The only requirement for event classes is to implement the \RabbitEvents\Publisher\ShouldPublish interface.
As an alternative, you could extend \RabbitEvents\Publisher\Support\AbstractPublishableEvent. This class was created to simplify the creation of event classes.
To publish this event, you just need to call the publish method of the event class and pass all the necessary data:
The method publish is provided by the trait Publishable.
Using the publish function
Sometimes, it is easier to use the helper function publish with an event key and payload:
Publish an Event object with the publish function
You can also use a combination of the two previous methods:
Publishing Protobuf Messages
You can publish Google Protobuf messages. The system will automatically handle serialization and set the content_type to application/x-protobuf.
Note: You must install the
rabbitevents/protobufpackage to use this feature.
The type header will be automatically set to App\Messages\AccountCreated, allowing the consumer to re-hydrate the object.
Testing
We always write tests. Tests in our applications contain many mocks and fakes to test how events are published.
There is the PublishableEventTesting trait that provides assertion methods in an Event class that you want to test.
Event.php
Test.php
If the assertion does not pass, Mockery\Exception\InvalidCountException will be thrown.\
Don't forget to call \Mockery::close() in tearDown or similar methods of your tests.