Skip to content

Commit 05eabda

Browse files
committed
add support of enqueue simple client.
1 parent 87748d6 commit 05eabda

7 files changed

+116
-6
lines changed

Command/ConsumeMessagesCommand.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace Enqueue\LaravelQueue\Command;
3+
4+
use Enqueue\SimpleClient\SimpleClient;
5+
6+
class ConsumeMessagesCommand extends \Enqueue\Symfony\Client\ConsumeMessagesCommand
7+
{
8+
public function __construct(SimpleClient $client)
9+
{
10+
parent::__construct(
11+
$client->getQueueConsumer(),
12+
$client->getDelegateProcessor(),
13+
$client->getQueueMetaRegistry(),
14+
$client->getDriver()
15+
);
16+
}
17+
}

Command/ProduceMessageCommand.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Enqueue\LaravelQueue\Command;
3+
4+
use Enqueue\SimpleClient\SimpleClient;
5+
6+
class ProduceMessageCommand extends \Enqueue\Symfony\Client\ProduceMessageCommand
7+
{
8+
public function __construct(SimpleClient $client)
9+
{
10+
parent::__construct($client->getProducer());
11+
}
12+
}

Command/QueuesCommand.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Enqueue\LaravelQueue\Command;
3+
4+
use Enqueue\SimpleClient\SimpleClient;
5+
6+
class QueuesCommand extends \Enqueue\Symfony\Client\Meta\QueuesCommand
7+
{
8+
public function __construct(SimpleClient $client)
9+
{
10+
parent::__construct($client->getQueueMetaRegistry());
11+
}
12+
}

Command/SetupBrokerCommand.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Enqueue\LaravelQueue\Command;
3+
4+
5+
use Enqueue\SimpleClient\SimpleClient;
6+
7+
class SetupBrokerCommand extends \Enqueue\Symfony\Client\SetupBrokerCommand
8+
{
9+
public function __construct(SimpleClient $client)
10+
{
11+
parent::__construct($client->getDriver());
12+
}
13+
}

Command/TopicsCommand.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Enqueue\LaravelQueue\Command;
3+
4+
use Enqueue\SimpleClient\SimpleClient;
5+
6+
class TopicsCommand extends \Enqueue\Symfony\Client\Meta\TopicsCommand
7+
{
8+
public function __construct(SimpleClient $client)
9+
{
10+
parent::__construct($client->getTopicMetaRegistry());
11+
}
12+
}

EnqueueServiceProvider.php

+47-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
namespace Enqueue\LaravelQueue;
44

5+
use Enqueue\LaravelQueue\Command\ConsumeMessagesCommand;
6+
use Enqueue\LaravelQueue\Command\ProduceMessageCommand;
7+
use Enqueue\LaravelQueue\Command\QueuesCommand;
8+
use Enqueue\LaravelQueue\Command\SetupBrokerCommand;
9+
use Enqueue\LaravelQueue\Command\TopicsCommand;
10+
use Enqueue\SimpleClient\SimpleClient;
511
use Illuminate\Queue\QueueManager;
612
use Illuminate\Support\ServiceProvider;
713

@@ -12,18 +18,53 @@ class EnqueueServiceProvider extends ServiceProvider
1218
*/
1319
public function boot()
1420
{
15-
/** @var QueueManager $manager */
16-
$manager = $this->app['queue'];
17-
18-
$manager->addConnector('interop', function () {
19-
return new Connector();
20-
});
21+
$this->bootInteropQueueDriver();
2122
}
2223

2324
/**
2425
* {@inheritdoc}
2526
*/
2627
public function register()
2728
{
29+
$this->registerClient();
30+
}
31+
32+
private function registerClient()
33+
{
34+
if (false == $this->app['config']->has('enqueue.client')) {
35+
return;
36+
}
37+
38+
if (false == class_exists(SimpleClient::class)) {
39+
throw new \LogicException('The enqueue/simple-client package is not installed');
40+
}
41+
42+
$this->app->singleton(SimpleClient::class, function() {
43+
/** @var \Illuminate\Config\Repository $config */
44+
$config = $this->app['config'];
45+
46+
var_dump($config->get('enqueue.client'));
47+
return new SimpleClient($config->get('enqueue.client'));
48+
});
49+
50+
if ($this->app->runningInConsole()) {
51+
$this->commands([
52+
SetupBrokerCommand::class,
53+
ProduceMessageCommand::class,
54+
QueuesCommand::class,
55+
TopicsCommand::class,
56+
ConsumeMessagesCommand::class,
57+
]);
58+
}
59+
}
60+
61+
private function bootInteropQueueDriver()
62+
{
63+
/** @var QueueManager $manager */
64+
$manager = $this->app['queue'];
65+
66+
$manager->addConnector('interop', function () {
67+
return new Connector();
68+
});
2869
}
2970
}

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"/Tests/"
2828
]
2929
},
30+
"suggest": {
31+
"enqueue/simple-client": "If you want to use enqueue client and cli commands"
32+
},
3033
"extra": {
3134
"branch-alias": {
3235
"dev-master": "0.6.x-dev"

0 commit comments

Comments
 (0)