Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 5e01afb

Browse files
committed
Merge remote-tracking branch 'origin/master'
Conflicts: README.md src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php
2 parents 974b693 + b2076e2 commit 5e01afb

File tree

4 files changed

+83
-32
lines changed

4 files changed

+83
-32
lines changed

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@ After composer update is finished you need to add ServiceProvider to your `provi
1515
Add these lines to your `app/config/queue.php` file to `connections` array:
1616

1717
'rabbitmq' => [
18-
'driver' => 'rabbitmq',
18+
'driver' => 'rabbitmq',
1919

20-
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
21-
'port' => env('RABBITMQ_PORT', 5672),
20+
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
21+
'port' => env('RABBITMQ_PORT', 5672),
2222

23-
'vhost' => env('RABBITMQ_VHOST', '/'),
24-
'login' => env('RABBITMQ_LOGIN', 'guest'),
25-
'password' => env('RABBITMQ_PASSWORD', 'guest'),
23+
'vhost' => env('RABBITMQ_VHOST', '/'),
24+
'login' => env('RABBITMQ_LOGIN', 'guest'),
25+
'password' => env('RABBITMQ_PASSWORD', 'guest'),
2626

27-
'queue' => env('RABBITMQ_QUEUE'), // name of the default queue,
28-
29-
'queue_params' => [
30-
'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
31-
'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
32-
'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
33-
'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
27+
'queue' => env('RABBITMQ_QUEUE'), // name of the default queue,
28+
29+
'exchange_declare' => env('RABBITMQ_EXCHANGE_DECLARE', true), // create the exchange if not exists
30+
'queue_declare_bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true), // create the queue if not exists and bind to the exchange
31+
32+
'queue_params' => [
33+
'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
34+
'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
35+
'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
36+
'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
3437
],
3538

3639
'exchange_params' => [

src/FintechFab/LaravelQueueRabbitMQ/LaravelQueueRabbitMQServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class LaravelQueueRabbitMQServiceProvider extends ServiceProvider
1313
*/
1414
public function register()
1515
{
16+
$this->mergeConfigFrom(
17+
__DIR__.'/../../config/rabbitmq.php', 'queue.connections.rabbitmq'
18+
);
1619
}
1720

1821
/**

src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class RabbitMQQueue extends Queue implements QueueContract
1515
protected $connection;
1616
protected $channel;
1717

18+
protected $declareExchange;
19+
protected $declareBindQueue;
20+
1821
protected $defaultQueue;
1922
protected $configQueue;
2023
protected $configExchange;
@@ -29,6 +32,8 @@ public function __construct(AMQPConnection $amqpConnection, $config)
2932
$this->defaultQueue = $config['queue'];
3033
$this->configQueue = $config['queue_params'];
3134
$this->configExchange = $config['exchange_params'];
35+
$this->declareExchange = $config['exchange_declare'];
36+
$this->declareBindQueue = $config['queue_declare_bind'];
3237

3338
$this->channel = $this->getChannel();
3439
}
@@ -142,26 +147,30 @@ private function declareQueue($name)
142147
$name = $this->getQueueName($name);
143148
$exchange = $this->configExchange['name'] ?:$name;
144149

145-
// declare queue
146-
$this->channel->queue_declare(
147-
$name,
148-
$this->configQueue['passive'],
149-
$this->configQueue['durable'],
150-
$this->configQueue['exclusive'],
151-
$this->configQueue['auto_delete']
152-
);
153-
154-
// declare exchange
155-
$this->channel->exchange_declare(
156-
$exchange,
157-
$this->configExchange['type'],
158-
$this->configExchange['passive'],
159-
$this->configExchange['durable'],
160-
$this->configExchange['auto_delete']
161-
);
150+
if ($this->declareExchange) {
151+
// declare exchange
152+
$this->channel->exchange_declare(
153+
$exchange,
154+
$this->configExchange['type'],
155+
$this->configExchange['passive'],
156+
$this->configExchange['durable'],
157+
$this->configExchange['auto_delete']
158+
);
159+
}
162160

163-
// bind queue to the exchange
164-
$this->channel->queue_bind($name, $exchange, $name);
161+
if ($this->declareBindQueue) {
162+
// declare queue
163+
$this->channel->queue_declare(
164+
$name,
165+
$this->configQueue['passive'],
166+
$this->configQueue['durable'],
167+
$this->configQueue['exclusive'],
168+
$this->configQueue['auto_delete']
169+
);
170+
171+
// bind queue to the exchange
172+
$this->channel->queue_bind($name, $exchange, $name);
173+
}
165174
}
166175

167176
/**

src/config/rabbitmq.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* default configuration for laravel-queue-rabbitmq merged with project config to base key 'queue'
5+
* @see \MapleSyrupGroup\AMQPEvents\Providers\AMQPEventServiceProvider
6+
*/
7+
return [
8+
9+
'driver' => 'rabbitmq',
10+
11+
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
12+
'port' => env('RABBITMQ_PORT', 5672),
13+
14+
'vhost' => env('RABBITMQ_VHOST', '/'),
15+
'login' => env('RABBITMQ_LOGIN', 'guest'),
16+
'password' => env('RABBITMQ_PASSWORD', 'guest'),
17+
18+
'queue' => env('RABBITMQ_QUEUE'), // name of the default queue,
19+
20+
'exchange_declare' => env('RABBITMQ_EXCHANGE_DECLARE', true), // create the exchange if not exists
21+
'queue_declare_bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true), // create the queue if not exists and bind to the exchange
22+
23+
'queue_params' => [
24+
'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
25+
'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
26+
'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
27+
'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
28+
],
29+
'exchange_params' => [
30+
'type' => env('RABBITMQ_EXCHANGE_TYPE', 'direct'), // more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
31+
'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),
32+
'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true), // the exchange will survive server restarts
33+
'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
34+
],
35+
36+
];

0 commit comments

Comments
 (0)