From f99eadcacb3cf597db53f7aaf71e218fdb9d6d8d Mon Sep 17 00:00:00 2001 From: Mohammadhossein Fereydouni Date: Mon, 15 May 2023 11:09:06 +0330 Subject: [PATCH] better nameing --- README.md | 10 +++++++--- config/rabbitmq.php | 4 ++-- .../{ConsumeMessages.php => ConsumeEventMessages.php} | 8 ++++---- ...{DeclareExchanges.php => DeclareEventExchanges.php} | 4 ++-- src/RabbitMQServiceProvider.php | 8 ++++---- 5 files changed, 19 insertions(+), 15 deletions(-) rename src/Commands/{ConsumeMessages.php => ConsumeEventMessages.php} (87%) rename src/Commands/{DeclareExchanges.php => DeclareEventExchanges.php} (94%) diff --git a/README.md b/README.md index 413089d..746bb3b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ return [ 'password' => env('RABBITMQ_PASSWORD', 'guest'), 'vhost' => env('RABBITMQ_VHOST', '/'), - 'consumers' => [ + 'event-consumers' => [ // [ // 'event' => '\App\Events\MyEvent', // 'routing_key' => 'my_routing_key', // if this event does not use routing key then remove this line @@ -64,8 +64,12 @@ If you want your event to be published using a routing key, then consider adding ### declare exchanges in rabbitmq server +```bash +php artisan rabbitmq:declare-event-exchanges +``` + When a laravel application wants to publish events, you must run this command to create appropriate exchanges on -RabbitMQ. +RabbitMQ (Exchanges will be created only for events specified in event service provider). For each event it will create an exchange with the name of event class. You can read more on exchanges types [here](https://www.rabbitmq.com/tutorials/amqp-concepts.html). @@ -93,7 +97,7 @@ If you have same event in both services (publisher and consumer) then you can om Then you can start consuming events with the following command: ```bash -php artisan rabbitmq:consume +php artisan rabbitmq:consume-events ``` ## Changelog diff --git a/config/rabbitmq.php b/config/rabbitmq.php index c7abd16..e0799fa 100644 --- a/config/rabbitmq.php +++ b/config/rabbitmq.php @@ -6,8 +6,8 @@ 'user' => env('RABBITMQ_USER', 'guest'), 'password' => env('RABBITMQ_PASSWORD', 'guest'), 'vhost' => env('RABBITMQ_VHOST', '/'), - - 'consumers' => [ + + 'event-consumers' => [ // [ // 'event' => '\App\Events\MyEvent', // 'routing_key' => 'my_routing_key', // if this event does not use routing key then remove this line diff --git a/src/Commands/ConsumeMessages.php b/src/Commands/ConsumeEventMessages.php similarity index 87% rename from src/Commands/ConsumeMessages.php rename to src/Commands/ConsumeEventMessages.php index beedcb5..0ed92bb 100644 --- a/src/Commands/ConsumeMessages.php +++ b/src/Commands/ConsumeEventMessages.php @@ -7,11 +7,11 @@ use Illuminate\Support\Str; use MHFereydouni\RabbitMQ\RabbitMQ; -class ConsumeMessages extends Command +class ConsumeEventMessages extends Command { - protected $signature = 'rabbitmq:consume'; + protected $signature = 'rabbitmq:consume-events'; - protected $description = 'consume rabbitmq messages'; + protected $description = 'consume events in the rabbitmq'; private array $events; @@ -19,7 +19,7 @@ public function __construct() { parent::__construct(); - $this->events = collect(config('rabbitmq.consumers')) + $this->events = collect(config('rabbitmq.event-consumers')) ->map(function ($event) { return [ 'base_event' => $event['event'], diff --git a/src/Commands/DeclareExchanges.php b/src/Commands/DeclareEventExchanges.php similarity index 94% rename from src/Commands/DeclareExchanges.php rename to src/Commands/DeclareEventExchanges.php index 64ef581..fae7dce 100644 --- a/src/Commands/DeclareExchanges.php +++ b/src/Commands/DeclareEventExchanges.php @@ -9,9 +9,9 @@ use MHFereydouni\RabbitMQ\RabbitMQ; use MHFereydouni\RabbitMQ\Support\ShouldPublish; -class DeclareExchanges extends Command +class DeclareEventExchanges extends Command { - protected $signature = 'rabbitmq:declare-exchanges'; + protected $signature = 'rabbitmq:declare-event-exchanges'; protected $description = 'declare exchanges'; diff --git a/src/RabbitMQServiceProvider.php b/src/RabbitMQServiceProvider.php index 970b166..fa2f03d 100644 --- a/src/RabbitMQServiceProvider.php +++ b/src/RabbitMQServiceProvider.php @@ -5,8 +5,8 @@ use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; use Illuminate\Events\Dispatcher; use Illuminate\Support\ServiceProvider; -use MHFereydouni\RabbitMQ\Commands\ConsumeMessages; -use MHFereydouni\RabbitMQ\Commands\DeclareExchanges; +use MHFereydouni\RabbitMQ\Commands\ConsumeEventMessages; +use MHFereydouni\RabbitMQ\Commands\DeclareEventExchanges; class RabbitMQServiceProvider extends ServiceProvider { @@ -32,8 +32,8 @@ public function boot() { if ($this->app->runningInConsole()) { $this->commands([ - DeclareExchanges::class, - ConsumeMessages::class, + DeclareEventExchanges::class, + ConsumeEventMessages::class, ]); }