Compare commits

...

4 Commits

Author SHA1 Message Date
6bfb91a50f Version 1.2.1
- Extended associated event not found exception message
- Args position. Fixed deprecated warning
- Queue auto-delete configuration support
2026-06-23 13:23:35 +04:00
505990e247 Extended associated event not found exception message 2026-06-23 13:16:57 +04:00
3147dde1c6 Args position. Fixed deprecated warning 2026-06-23 13:16:35 +04:00
dce2a19295 Queue auto-delete configuration support 2026-06-23 13:15:57 +04:00
9 changed files with 344 additions and 313 deletions

View File

@@ -207,6 +207,7 @@ 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
@@ -223,6 +224,7 @@ 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.* \

View File

@@ -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.0",
"version": "1.2.1",
"keywords": [
"laravel", "rabbitmq", "event", "emit", "microservice",
"pipeline", "data exchanging", "message", "broker", "php8",

621
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,7 +24,7 @@ class Consume extends Command
/**
* @var string
*/
protected $signature = 'rabbitmq:consume {--connection=} {--queue=} {--exchange=} {--exchange-type=} {--exchange-is-default} {--routing-key=} {--tag=}';
protected $signature = 'rabbitmq:consume {--connection=} {--queue=} {--queue-auto-delete} {--exchange=} {--exchange-type=} {--exchange-is-default} {--routing-key=} {--tag=}';
/**
* @var string
@@ -99,7 +99,9 @@ class Consume extends Command
{
return new Queue(
name: $params->queue->value() ?? 'default',
declaration: new QueueDeclaration(),
declaration: new QueueDeclaration(
autoDelete: $params->queueAutoDelete->toBool()
),
bindings: new QueueBindings($params->routingKey->toString()),
);
}
@@ -107,8 +109,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()
);

View File

@@ -10,6 +10,7 @@ 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
@@ -20,6 +21,7 @@ class ConsumerParameters extends Dto
{
protected Property $connection;
protected Property $queue;
protected Property $queueAutoDelete;
protected Property $exchange;
protected Property $routingKey;
protected Property $exchangeType;

View File

@@ -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(),
);
}

View File

@@ -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

View File

@@ -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

View File

@@ -45,6 +45,16 @@ class EventMapper implements EventMapperInterface
}
}
throw new AssociatedEventNotFound(json_encode($payload));
$error = <<<ERR
Not found event.
Queue: %s
Routing key: %s
Payload: %s
ERR;
throw new AssociatedEventNotFound(
sprintf($error, $queueName, $routingKey, json_encode($payload))
);
}
}