1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。 |
5
|
|
|
* |
6
|
|
|
* This file is part of the milkmeowo/laravel-mns. |
7
|
|
|
* |
8
|
|
|
* (c) Milkmeowo <[email protected]> |
9
|
|
|
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license that is bundled |
12
|
|
|
* with this source code in the file LICENSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Milkmeowo\LaravelMns\Console; |
16
|
|
|
|
17
|
|
|
use AliyunMNS\Client; |
18
|
|
|
use Illuminate\Console\Command; |
19
|
|
|
use AliyunMNS\Exception\MnsException; |
20
|
|
|
use AliyunMNS\Requests\ListQueueRequest; |
21
|
|
|
|
22
|
|
|
class MnsListQueueCommand extends Command |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $signature = 'queue:mns:list {--p|prefix} {--connection=mns}'; |
28
|
|
|
/** |
29
|
|
|
* The console command description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $description = 'List MNS Queue'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the console command. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function handle() |
41
|
|
|
{ |
42
|
|
|
$connection = $this->option('connection'); |
43
|
|
|
$config = config("queue.connections.{$connection}"); |
44
|
|
|
|
45
|
|
|
$client = new Client($config['endpoint'], $config['key'], $config['secret']); |
46
|
|
|
|
47
|
|
|
$prefix = null; |
48
|
|
|
if ($this->option('prefix')) { |
49
|
|
|
$prefix = $this->ask('请填写prefix'); |
50
|
|
|
} |
51
|
|
|
$this->listQueue($client, $prefix); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* 列出队列内容. |
56
|
|
|
* |
57
|
|
|
* @param Client $client MNS Client |
58
|
|
|
* @param null $prefix 前缀 |
59
|
|
|
* @param null $marker marker |
60
|
|
|
*/ |
61
|
|
|
public function listQueue(Client $client, $prefix = null, $marker = null) |
62
|
|
|
{ |
63
|
|
|
$request = new ListQueueRequest(null, $prefix, $marker); |
64
|
|
|
|
65
|
|
|
try { |
66
|
|
|
$res = $client->listQueue($request); |
67
|
|
|
$this->info('查询队列成功'); |
68
|
|
|
foreach ($res->getQueueNames() as $queueName) { |
69
|
|
|
$this->info($queueName); |
70
|
|
|
} |
71
|
|
|
$marker = $res->getNextMarker(); |
72
|
|
|
if ($marker) { |
73
|
|
|
$this->question('---下一页:[' . base64_decode($marker) . ']---'); |
74
|
|
|
$this->listQueue($client, $prefix, $marker); |
75
|
|
|
} |
76
|
|
|
} catch (MnsException $e) { |
77
|
|
|
$this->error('查询队列失败:' . $e); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|