Compare commits
2 Commits
main
...
8320fb4a84
| Author | SHA1 | Date | |
|---|---|---|---|
| 8320fb4a84 | |||
| c481c961fb |
10
README.md
10
README.md
@@ -33,9 +33,8 @@ return [
|
||||
|
||||
### 1. Creating regular events for publishing to a RabbitMQ
|
||||
|
||||
Create an event that implements the `Broadcast` interface.
|
||||
Your event should implements `JsonSerializable` interface if
|
||||
default serializer is used.
|
||||
Create an event that implements the `Broadcast` interface. `Broadcast` interface
|
||||
extends `JsonSerializable` then your event should implements `jsonSerialize` method.
|
||||
|
||||
```php
|
||||
namespace App\Events;
|
||||
@@ -43,9 +42,8 @@ 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, JsonSerializable
|
||||
class UserCreated implements Broadcast
|
||||
{
|
||||
use Dispatchable, BroadcastEvent;
|
||||
|
||||
@@ -207,7 +205,6 @@ Consumer will listen rabbitmq bus and emit mapped event from as regular laravel
|
||||
#
|
||||
# --connection=default - Connection name from config
|
||||
# --queue=default - Queue
|
||||
# --queue-auto-delete - Queue auto-delete config
|
||||
# --exchange=amq.direct - Exchange name
|
||||
# --exchange-type=direct - Exchange type
|
||||
# --exchange-is-default - Exchange is default, required for default exchanges
|
||||
@@ -224,7 +221,6 @@ php artisan rabbitmq:consume
|
||||
php artisan rabbitmq:consume \
|
||||
--connection=default \
|
||||
--queue=service.users \
|
||||
--queue-auto-delete \
|
||||
--exchange=amq.direct \
|
||||
--exchange-type=direct \
|
||||
--routing-key=user.* \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "A laravel package for events emitting between services using RabbitMQ as message broker.",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.0",
|
||||
"keywords": [
|
||||
"laravel", "rabbitmq", "event", "emit", "microservice",
|
||||
"pipeline", "data exchanging", "message", "broker", "php8",
|
||||
|
||||
686
composer.lock
generated
686
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,7 @@ class Consume extends Command
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'rabbitmq:consume {--connection=} {--queue=} {--queue-auto-delete} {--exchange=} {--exchange-type=} {--exchange-is-default} {--routing-key=} {--tag=}';
|
||||
protected $signature = 'rabbitmq:consume {--connection=} {--queue=} {--exchange=} {--exchange-type=} {--exchange-is-default} {--routing-key=} {--tag=}';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -99,9 +99,7 @@ class Consume extends Command
|
||||
{
|
||||
return new Queue(
|
||||
name: $params->queue->value() ?? 'default',
|
||||
declaration: new QueueDeclaration(
|
||||
autoDelete: $params->queueAutoDelete->toBool()
|
||||
),
|
||||
declaration: new QueueDeclaration(),
|
||||
bindings: new QueueBindings($params->routingKey->toString()),
|
||||
);
|
||||
}
|
||||
@@ -109,8 +107,8 @@ class Consume extends Command
|
||||
private function getExchange(ConsumerParameters $params): Exchange
|
||||
{
|
||||
return new Exchange(
|
||||
name: $params->exchange->toString() ?: 'amq.direct',
|
||||
type: $params->exchangeType->toString() ?: 'direct',
|
||||
name: $params->exchange->toString() ?? 'amq.direct',
|
||||
type: $params->exchangeType->toString() ?? 'direct',
|
||||
isDefault: $params->exchangeIsDefault->toBool(),
|
||||
declaration: new ExchangeDeclaration()
|
||||
);
|
||||
|
||||
@@ -10,7 +10,6 @@ use Diffhead\PHP\Dto\Property;
|
||||
/**
|
||||
* @property \Diffhead\PHP\Dto\Property<string|null> $connection
|
||||
* @property \Diffhead\PHP\Dto\Property<string|null> $queue
|
||||
* @property \Diffhead\PHP\Dto\Property<bool> $queueAutoDelete
|
||||
* @property \Diffhead\PHP\Dto\Property<string|null> $exchange
|
||||
* @property \Diffhead\PHP\Dto\Property<string|null> $routingKey
|
||||
* @property \Diffhead\PHP\Dto\Property<string|null> $exchangeType
|
||||
@@ -21,7 +20,6 @@ class ConsumerParameters extends Dto
|
||||
{
|
||||
protected Property $connection;
|
||||
protected Property $queue;
|
||||
protected Property $queueAutoDelete;
|
||||
protected Property $exchange;
|
||||
protected Property $routingKey;
|
||||
protected Property $exchangeType;
|
||||
|
||||
@@ -33,21 +33,21 @@ class PublishEvent implements ShouldQueue
|
||||
$config = $this->configuration->getConnection($event->getConnection());
|
||||
|
||||
$exchange = new Exchange(
|
||||
declaration: new ExchangeDeclaration(),
|
||||
name: $event->getExchange(),
|
||||
type: $event->getExchangeType(),
|
||||
isDefault: $event->getExchangeIsDefault(),
|
||||
declaration: new ExchangeDeclaration()
|
||||
);
|
||||
|
||||
$queue = null;
|
||||
|
||||
if ($event->getQueue()) {
|
||||
$queue = new Queue(
|
||||
name: $event->getQueue(),
|
||||
declaration: new QueueDeclaration(),
|
||||
bindings: new QueueBindings(
|
||||
routingKey: $event->getRoutingKey()
|
||||
),
|
||||
name: $event->getQueue(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace Diffhead\PHP\LaravelRabbitMQ\Object;
|
||||
class Exchange
|
||||
{
|
||||
public function __construct(
|
||||
private ExchangeDeclaration $declaration,
|
||||
private string $name = 'amq.direct',
|
||||
private string $type = 'direct',
|
||||
private bool $isDefault = true,
|
||||
private ExchangeDeclaration $declaration,
|
||||
) {}
|
||||
|
||||
public function name(): string
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace Diffhead\PHP\LaravelRabbitMQ\Object;
|
||||
class Queue
|
||||
{
|
||||
public function __construct(
|
||||
private string $name = 'default',
|
||||
private QueueDeclaration $declaration,
|
||||
private QueueBindings $bindings,
|
||||
private string $name = 'default',
|
||||
) {}
|
||||
|
||||
public function name(): string
|
||||
|
||||
@@ -45,16 +45,6 @@ class EventMapper implements EventMapperInterface
|
||||
}
|
||||
}
|
||||
|
||||
$error = <<<ERR
|
||||
Not found event.
|
||||
|
||||
Queue: %s
|
||||
Routing key: %s
|
||||
Payload: %s
|
||||
ERR;
|
||||
|
||||
throw new AssociatedEventNotFound(
|
||||
sprintf($error, $queueName, $routingKey, json_encode($payload))
|
||||
);
|
||||
throw new AssociatedEventNotFound(json_encode($payload));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user