2
2
3
3
namespace Enqueue \LaravelQueue ;
4
4
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 ;
5
11
use Illuminate \Queue \QueueManager ;
6
12
use Illuminate \Support \ServiceProvider ;
7
13
@@ -12,18 +18,53 @@ class EnqueueServiceProvider extends ServiceProvider
12
18
*/
13
19
public function boot ()
14
20
{
15
- /** @var QueueManager $manager */
16
- $ manager = $ this ->app ['queue ' ];
17
-
18
- $ manager ->addConnector ('interop ' , function () {
19
- return new Connector ();
20
- });
21
+ $ this ->bootInteropQueueDriver ();
21
22
}
22
23
23
24
/**
24
25
* {@inheritdoc}
25
26
*/
26
27
public function register ()
27
28
{
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
+ });
28
69
}
29
70
}
0 commit comments