|
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 AliyunMNS\Model\Message; |
|
19
|
|
|
use Illuminate\Console\Command; |
|
20
|
|
|
|
|
21
|
|
|
class MnsShowQueueCommand extends Command |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The name and signature of the console command. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $signature = 'queue:mns:show {queue?} {num?} {--c|connection=mns}'; |
|
29
|
|
|
/** |
|
30
|
|
|
* The console command description. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $description = '显示 MNS Queue'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle() |
|
42
|
|
|
{ |
|
43
|
|
|
$queueName = $this->argument('queue'); |
|
44
|
|
|
$showNum = $this->argument('num') ?: 15; |
|
45
|
|
|
$connection = $this->option('connection'); |
|
46
|
|
|
$config = config("queue.connections.{$connection}"); |
|
47
|
|
|
if (!$queueName) { |
|
48
|
|
|
$queueName = $config['queue']; |
|
49
|
|
|
} |
|
50
|
|
|
$client = new Client($config['endpoint'], $config['key'], $config['secret']); |
|
51
|
|
|
$queue = $client->getQueueRef($queueName); |
|
52
|
|
|
$this->alert('队列:' . $queueName); |
|
53
|
|
|
$this->info('拉取信息中...'); |
|
54
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
$response = $queue->batchPeekMessage($showNum); |
|
57
|
|
|
if ($messages = $response->getMessages()) { |
|
58
|
|
|
/** |
|
59
|
|
|
* @var Message |
|
60
|
|
|
*/ |
|
61
|
|
|
foreach ($messages as $message) { |
|
62
|
|
|
$this->info('------------'); |
|
63
|
|
|
$this->info('消息编号' . $message->getMessageId()); |
|
64
|
|
|
$this->info('消息正文的 MD5 值' . $message->getMessageBodyMD5()); |
|
65
|
|
|
$this->info('消息正文' . $message->getMessageBody()); |
|
66
|
|
|
$this->info('消息发送到队列的时间' . $message->getEnqueueTime()); |
|
67
|
|
|
$this->info('第一次被消费的时间' . $message->getFirstDequeueTime()); |
|
68
|
|
|
$this->info('总共被消费的次数' . $message->getDequeueCount()); |
|
69
|
|
|
$this->info('消息的优先级权值' . $message->getPriority()); |
|
70
|
|
|
$this->info('------------'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} catch (\Exception $e) { |
|
74
|
|
|
$this->info('队列中没消息'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|