Skip to content

Commit

Permalink
better nameing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhfereydouni committed May 15, 2023
1 parent 706418f commit f99eadc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/rabbitmq.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
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;

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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions src/RabbitMQServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,8 +32,8 @@ public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
DeclareExchanges::class,
ConsumeMessages::class,
DeclareEventExchanges::class,
ConsumeEventMessages::class,
]);
}

Expand Down

0 comments on commit f99eadc

Please sign in to comment.