Skip to content

Commit db64d05

Browse files
committed
update flow
1 parent 708d3f6 commit db64d05

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

config/rabbitmq.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,25 @@
99

1010
'driver' => 'rabbitmq',
1111
'queue' => env('RABBITMQ_QUEUE', 'default'),
12-
'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::create_connection([
12+
'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
13+
14+
'hosts' => [
1315
[
1416
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
1517
'port' => env('RABBITMQ_PORT', 5672),
1618
'user' => env('RABBITMQ_USER', 'guest'),
1719
'password' => env('RABBITMQ_PASSWORD', 'guest'),
1820
'vhost' => env('RABBITMQ_VHOST', '/'),
19-
]
20-
], [
21-
// 'ssl_options' => [
22-
// 'cafile' => env('RABBITMQ_SSL_CAFILE', null),
23-
// 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
24-
// 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
25-
// 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
26-
// 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
27-
// ],
28-
'heartbeat' => 0
29-
]),
21+
],
22+
],
3023

3124
'options' => [
3225
'queue' => [
3326
'job' => Botika\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
3427
],
3528
],
3629

37-
/*
30+
/**
3831
* Set to "horizon" if you wish to use Laravel Horizon.
3932
*/
4033
'worker' => env('RABBITMQ_WORKER', 'default'),

src/LaravelQueueRabbitMQServiceProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\ServiceProvider;
88
use Botika\LaravelQueueRabbitMQ\Console\ConsumeCommand;
99
use Botika\LaravelQueueRabbitMQ\Queue\Connectors\RabbitMQConnector;
10+
use PhpAmqpLib\Connection\AMQPStreamConnection;
1011

1112
class LaravelQueueRabbitMQServiceProvider extends ServiceProvider
1213
{
@@ -69,7 +70,11 @@ public function boot(): void
6970
$queue = $this->app['queue'];
7071

7172
$queue->addConnector('rabbitmq', function () {
72-
return new RabbitMQConnector($this->app['events']);
73+
/** @var \PhpAmqpLib\Connection\AbstractConnection $connection */
74+
$connection = config('queue.connections.rabbitmq.connection', \PhpAmqpLib\Connection\AMQPLazyConnection::class)::create_connection(
75+
config('queue.connections.rabbitmq.hosts', [])
76+
);
77+
return new RabbitMQConnector($this->app['events'], $connection);
7378
});
7479
}
7580
}

src/Queue/Connectors/RabbitMQConnector.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ class RabbitMQConnector implements ConnectorInterface
2323
*/
2424
private $dispatcher;
2525

26-
public function __construct(Dispatcher $dispatcher)
26+
private $connection;
27+
28+
/**
29+
* Constructor
30+
*
31+
* @param Dispatcher $dispatcher
32+
* @param AbstractConnection $connection
33+
*/
34+
public function __construct(Dispatcher $dispatcher, AbstractConnection $connection)
2735
{
2836
$this->dispatcher = $dispatcher;
37+
$this->connection = $connection;
2938
}
3039

3140
/**
@@ -40,7 +49,7 @@ public function connect(array $config): Queue
4049
{
4150
$queue = $this->createQueue(
4251
Arr::get($config, 'worker', 'default'),
43-
Arr::get($config, 'connection'),
52+
$this->connection,
4453
$config['queue'],
4554
Arr::get($config, 'after_commit', false),
4655
Arr::get($config, 'options.queue', [])

0 commit comments

Comments
 (0)