| Total Complexity | 3 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | class MnsCreateQueueCommand extends Command |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * The name and signature of the console command. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $signature = 'queue:mns:create {queue?} {--c|connection=mns}'; |
||
| 30 | /** |
||
| 31 | * The console command description. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $description = '创建 MNS Queue'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Execute the console command. |
||
| 39 | * |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function handle() |
||
| 43 | { |
||
| 44 | $queue = $this->argument('queue'); |
||
| 45 | $connection = $this->option('connection'); |
||
| 46 | $config = config("queue.connections.{$connection}"); |
||
| 47 | if (!$queue) { |
||
| 48 | $queue = $this->ask('请输入队列名称'); |
||
| 49 | } |
||
| 50 | |||
| 51 | try { |
||
| 52 | $client = new Client($config['endpoint'], $config['key'], $config['secret']); |
||
| 53 | $request = new CreateQueueRequest($queue); |
||
| 54 | $client->createQueue($request); |
||
| 55 | $this->info('队列创建成功'); |
||
| 56 | $this->alert($queue); |
||
| 57 | } catch (MnsException $e) { |
||
| 58 | $this->error('队列创建失败:' . $e); |
||
| 59 | } |
||
| 62 |