Skip to content

Commit 24874ce

Browse files
committed
make it work with other amqp implementations.
1 parent d231d60 commit 24874ce

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ RabbitMQ Queue driver for Laravel
1111
1. Install this package via composer using:
1212

1313
```
14-
composer require vladimir-yuldashev/laravel-queue-rabbitmq:5.5
14+
composer require vladimir-yuldashev/laravel-queue-rabbitmq:^6
1515
```
1616

1717
2. Add these properties to `.env` with proper values:
1818

1919
```
2020
QUEUE_DRIVER=rabbitmq
2121
22-
RABBITMQ_HOST=127.0.0.1
23-
RABBITMQ_PORT=5672
24-
RABBITMQ_VHOST=/
25-
RABBITMQ_LOGIN=guest
26-
RABBITMQ_PASSWORD=guest
22+
RABBITMQ_DSN=amqp://guest:guest@127.0.0.1:5672/%2F
2723
RABBITMQ_QUEUE=queue_name
2824
```
2925

config/rabbitmq.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
'driver' => 'rabbitmq',
1111

12+
'dsn' => env('RABBITMQ_DSN', null),
13+
14+
/*
15+
* Could be one a class that implements \Interop\Amqp\AmqpConnectionFactory for example:
16+
* - \EnqueueAmqpExt\AmqpConnectionFactory if you install enqueue/amqp-ext
17+
* - \EnqueueAmqpLib\AmqpConnectionFactory if you install enqueue/amqp-lib
18+
* - \EnqueueAmqpBunny\AmqpConnectionFactory if you install enqueue/amqp-bunny
19+
*/
20+
'factory_class' => \Enqueue\AmqpLib\AmqpConnectionFactory::class,
21+
1222
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
1323
'port' => env('RABBITMQ_PORT', 5672),
1424

src/Queue/Connectors/RabbitMQConnector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Contracts\Queue\Queue;
88
use Illuminate\Queue\Connectors\ConnectorInterface;
99
use Illuminate\Queue\Events\WorkerStopping;
10+
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
1011
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
1112

1213
class RabbitMQConnector implements ConnectorInterface
@@ -20,7 +21,14 @@ class RabbitMQConnector implements ConnectorInterface
2021
*/
2122
public function connect(array $config): Queue
2223
{
23-
$factory = new AmqpConnectionFactory([
24+
$factoryClass = $config['factory_class'];
25+
if (false == class_exists($factoryClass) || false == (new \ReflectionClass($factoryClass))->implementsInterface(InteropAmqpConnectionFactory::class)) {
26+
throw new \LogicException(sprintf('The factory_class option has to be valid class that implements "%s"', InteropAmqpConnectionFactory::class));
27+
}
28+
29+
30+
$factory = new $factoryClass([
31+
'dsn' => $config['dsn'],
2432
'host' => $config['host'],
2533
'port' => $config['port'],
2634
'user' => $config['login'],

0 commit comments

Comments
 (0)