Added PublishEvent listener connection and queue configuration feature

This commit is contained in:
2025-12-31 16:39:48 +04:00
parent 7ae585ae29
commit 739a1a6bef
11 changed files with 325 additions and 314 deletions

View File

@@ -2,6 +2,11 @@
return [
'connections' => [
/**
* This section helps you to configure
* RabbitMQ connections for consumers or events
* publishing.
*/
'default' => [
'host' => env('RABBITMQ_HOST', 'localhost'),
'port' => env('RABBITMQ_PORT', 5672),
@@ -11,10 +16,23 @@ return [
]
],
'message' => [
/**
* Serializer converts a PHP object into \PhpAmqpLib\Message\AMQPMessage
*/
'serializer' => \Diffhead\PHP\LaravelRabbitMQ\Service\Serializer::class,
/**
* Unserializer converts \PhpAmqpLib\Message\AMQPMessage into a PHP array
*/
'unserializer' => \Diffhead\PHP\LaravelRabbitMQ\Service\Unserializer::class,
],
'event' => [
/**
* \Diffhead\PHP\LaravelRabbitMQ\Trait\BroadcastEvent
*
* This trait helps you to configure where the event should be broadcasted
* by default. You can override these settings directly in the event class
* or globally using environment variables.
*/
'defaults' => [
'connection' => env('RABBITMQ_EVENT_CONNECTION', 'default'),
'queue' => env('RABBITMQ_EVENT_QUEUE', 'default'),
@@ -23,11 +41,30 @@ return [
'exchange_is_default' => (bool) env('RABBITMQ_EVENT_EXCHANGE_IS_DEFAULT', true),
'routing_key' => (string) env('RABBITMQ_EVENT_ROUTING_KEY', ''),
],
/**
* \Diffhead\PHP\LaravelRabbitMQ\Listener\PublishEvent
*
* This listener publishes events to a rabbitmq bus and
* does that using laravel queues.
*
* You can configure which connection and queue to use for.
*/
'publishing' => [
'connection' => env('RABBITMQ_EVENT_PUBLISHING_CONNECTION', 'sync'),
'queue' => env('RABBITMQ_EVENT_PUBLISHING_QUEUE', 'default'),
],
/**
* This mapper detects event which should
* be emitted when RabbitMQ message received.
*/
'mapper' => \Diffhead\PHP\LaravelRabbitMQ\Service\EventMapper::class,
/**
* Map events with their queues and routing keys.
*/
'map' => [
/**
* Example:
*
*
* \App\Shared\Event\User\UserCreated::class => [
* 'queues' => ['portal.calendar.users'],
* 'routing_keys' => ['user.created'],
@@ -38,6 +75,5 @@ return [
* ],
*/
],
]
];