Compare commits
2 Commits
8320fb4a84
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| ac735d8bf5 | |||
| 6b044074ce |
@@ -33,8 +33,9 @@ return [
|
||||
|
||||
### 1. Creating regular events for publishing to a RabbitMQ
|
||||
|
||||
Create an event that implements the `Broadcast` interface. `Broadcast` interface
|
||||
extends `JsonSerializable` then your event should implements `jsonSerialize` method.
|
||||
Create an event that implements the `Broadcast` interface.
|
||||
Your event should implements `JsonSerializable` interface if
|
||||
default serializer is used.
|
||||
|
||||
```php
|
||||
namespace App\Events;
|
||||
@@ -42,8 +43,9 @@ namespace App\Events;
|
||||
use Diffhead\PHP\LaravelRabbitMQ\Event\Broadcast;
|
||||
use Diffhead\PHP\LaravelRabbitMQ\Trait\BroadcastEvent;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use JsonSerializable;
|
||||
|
||||
class UserCreated implements Broadcast
|
||||
class UserCreated implements Broadcast, JsonSerializable
|
||||
{
|
||||
use Dispatchable, BroadcastEvent;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "A laravel package for events emitting between services using RabbitMQ as message broker.",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"keywords": [
|
||||
"laravel", "rabbitmq", "event", "emit", "microservice",
|
||||
"pipeline", "data exchanging", "message", "broker", "php8",
|
||||
|
||||
588
composer.lock
generated
588
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Diffhead\PHP\LaravelRabbitMQ\Event;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
interface Broadcast extends JsonSerializable
|
||||
interface Broadcast
|
||||
{
|
||||
public function getConnection(): string;
|
||||
public function getQueue(): string;
|
||||
|
||||
@@ -11,16 +11,16 @@ use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
class Serializer implements SerializerInterface
|
||||
{
|
||||
public function serialize(object $data): AMQPMessage
|
||||
public function serialize(object $event): AMQPMessage
|
||||
{
|
||||
if ($data instanceof JsonSerializable) {
|
||||
if ($event instanceof JsonSerializable) {
|
||||
return new AMQPMessage(
|
||||
json_encode($data->jsonSerialize())
|
||||
json_encode($event->jsonSerialize())
|
||||
);
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
'Data should be an instance of BroadcastEvent'
|
||||
'Event should be an instance of JsonSerializable'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user