Skip to content

Commit 24f3b08

Browse files
committed
define exchange type and flags, will use AMQP_EX_TYPE_DIRECT and AMQP_DURABLE by default
1 parent 6b18ee9 commit 24f3b08

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

src/FintechFab/LaravelQueueRabbitMQ/Queue/Connectors/RabbitMQConnector.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ public function connect(array $config)
2121
$connection = new AMQPConnection($config);
2222
$connection->connect();
2323

24+
if (!isset($config['exchange_type'])) {
25+
$config['exchange_type'] = AMQP_EX_TYPE_DIRECT;
26+
}
27+
28+
if (!isset($config['exchange_flags'])) {
29+
$config['exchange_flags'] = AMQP_DURABLE;
30+
}
31+
2432
return new RabbitMQQueue(
2533
$connection,
2634
$config['queue'],
27-
$config['exchange_name']
35+
$config['exchange_name'],
36+
$config['exchange_type'],
37+
$config['exchange_flags']
2838
);
2939
}
3040
}

src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ class RabbitMQQueue extends Queue implements QueueInterface
1818
protected $exchange;
1919
protected $default_queue;
2020
protected $exchange_name;
21+
protected $exchange_type;
22+
protected $exchange_flags;
2123

2224
/**
2325
* @param AMQPConnection $amqpConnection
2426
* @param string $default_queue
2527
* @param string $exchange_name
2628
*
27-
* @internal param string $routing_key
29+
* @param mixed $exchange_type
30+
* @param mixed $exchange_flags
2831
*/
29-
public function __construct(AMQPConnection $amqpConnection, $default_queue, $exchange_name)
32+
public function __construct(AMQPConnection $amqpConnection, $default_queue, $exchange_name, $exchange_type, $exchange_flags)
3033
{
3134
$this->connection = $amqpConnection;
3235
$this->default_queue = $default_queue;
3336
$this->exchange_name = $exchange_name;
37+
$this->exchange_type = $exchange_type;
38+
$this->exchange_flags = $exchange_flags;
3439
$this->channel = $this->getChannel();
3540
$this->exchange = $this->getExchange($this->channel);
3641
}
@@ -164,7 +169,8 @@ public function getExchange(AMQPChannel $channel)
164169
{
165170
$exchange = new AMQPExchange($channel);
166171
$exchange->setName($this->exchange_name);
167-
$exchange->setType(AMQP_EX_TYPE_DIRECT);
172+
$exchange->setFlags($this->exchange_flags);
173+
$exchange->setType($this->exchange_type);
168174
$exchange->declareExchange();
169175

170176
return $exchange;

src/examples/queue.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@
1212
'connections' => array(
1313

1414
'rabbitmq' => array(
15-
'driver' => 'rabbitmq',
15+
'driver' => 'rabbitmq',
1616

17-
'host' => '',
18-
'port' => '',
17+
'host' => '',
18+
'port' => '',
19+
20+
'vhost' => '',
21+
'login' => '',
22+
'password' => '',
23+
24+
'queue' => '', // name of the default queue
25+
26+
'exchange_name' => '', // name of the exchange
27+
28+
// Type of your exchange
29+
// Can be AMQP_EX_TYPE_DIRECT or AMQP_EX_TYPE_FANOUT
30+
// see documentation for more info
31+
// http://www.rabbitmq.com/tutorials/amqp-concepts.html
32+
'exchange_type' => AMQP_EX_TYPE_DIRECT,
33+
'exchange_flags' => AMQP_DURABLE,
1934

20-
'vhost' => '',
21-
'login' => '',
22-
'password' => '',
2335

24-
'queue' => '', // name of the default queue
25-
'exchange_name' => '', // name of the exchange
2636
),
2737

2838
),

0 commit comments

Comments
 (0)