Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
milkmeowo authored and StyleCIBot committed Jun 1, 2018
1 parent ed96e9a commit 759a404
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 109 deletions.
65 changes: 41 additions & 24 deletions src/Adaptors/MnsAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
*
* This file is part of the milkmeowo/laravel-mns.
*
* (c) Milkmeowo <[email protected]>
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Milkmeowo\LaravelMns\Adaptors;

use AliyunMNS\AsyncCallback;
Expand Down Expand Up @@ -27,7 +39,7 @@
use AliyunMNS\Responses\SetQueueAttributeResponse;

/**
* Class MNSAdapter
* Class MNSAdapter.
*
* @method string getQueueName()
* @method SetQueueAttributeResponse setAttribute(QueueAttributes $attributes)
Expand Down Expand Up @@ -61,22 +73,23 @@ class MnsAdapter
*/
const ADAPTER_TO_ALIYUN_MNS_SDK_VERSION = '1.3.5@2017-06-06';
/**
* Aliyun MNS Client
* Aliyun MNS Client.
*
* @var MnsClient $client
* @var MnsClient
*/
private $client;
/**
* Aliyun MNS SDK Queue.
*
* @var Queue $queue
* @var Queue
*/
private $queue;

/**
* MnsAdapter constructor.
*
* @param MnsClient $client
* @param string $queue
* @param string $queue
*/
public function __construct(MnsClient $client, string $queue)
{
Expand Down Expand Up @@ -111,11 +124,12 @@ public function useQueue($queue)
if (null != $queue) {
$this->queue = $this->client->getQueueRef($queue);
}

return $this;
}

/**
* 创建队列
* 创建队列.
*
* @param string $queueName 队列名
*/
Expand All @@ -124,16 +138,17 @@ public function createQueue($queueName)
try {
$request = new CreateQueueRequest($queueName);
$response = $this->client->createQueue($request);

return $response->isSucceed();
} catch (MnsException $e) {
}
}

/**
* 异步创建队列
* 异步创建队列.
*
* @param string $queueName 队列名
* @param AsyncCallback|null $callback 异步回调
* @param string $queueName 队列名
* @param AsyncCallback|null $callback 异步回调
*/
public function createQueueAsync($queueName, AsyncCallback $callback = null)
{
Expand All @@ -145,64 +160,66 @@ public function createQueueAsync($queueName, AsyncCallback $callback = null)
}

/**
* 获取队列列表
* 获取队列列表.
*
* @param null $retNum 单次请求结果的最大返回个数,可以取1-1000范围内的整数值,默认值为1000。
* @param null $prefix 按照该前缀开头的 queueName 进行查找。
* @param null $marker 请求下一个分页的开始位置,一般从上次分页结果返回的NextMarker获取。
*
* @return \AliyunMNS\Responses\ListQueueResponse
*/
public function listQueue($retNum = null, $prefix = null, $marker = null)
{
try {
$request = new ListQueueRequest($retNum, $prefix, $marker);

return $this->client->listQueue($request);
} catch (MnsException $e) {

}
}

/**
* 获取队列列表
* 获取队列列表.
*
* @param int $retNum 单次请求结果的最大返回个数,可以取1-1000范围内的整数值,默认值为1000。
* @param string $prefix 按照该前缀开头的 queueName 进行查找。
* @param string $marker 请求下一个分页的开始位置,一般从上次分页结果返回的NextMarker获取。
* @param AsyncCallback|null $callback
*
* @param int $retNum 单次请求结果的最大返回个数,可以取1-1000范围内的整数值,默认值为1000。
* @param string $prefix 按照该前缀开头的 queueName 进行查找。
* @param string $marker 请求下一个分页的开始位置,一般从上次分页结果返回的NextMarker获取。
* @param AsyncCallback|NULL $callback
* @return mixed
*/
public function listQueueAsync($retNum = NULL, $prefix = NULL, $marker = NULL, AsyncCallback $callback = NULL)
public function listQueueAsync($retNum = null, $prefix = null, $marker = null, AsyncCallback $callback = null)
{
try {
$request = new ListQueueRequest($retNum, $prefix, $marker);

return $this->client->listQueueAsync($request, $callback);
} catch (MnsException $e) {

}

}

/**
* 删除队列
* 删除队列.
*
* @param string $queueName 队列名
*/
public function deleteQueue($queueName)
{
try {
$response = $this->client->deleteQueue($queueName);

return $response->isSucceed();
} catch (MnsException $e) {
}
}

/**
* 异步删除队列
* 异步删除队列.
*
* @param string $queueName 队列名
* @param AsyncCallback|NULL $callback
* @param string $queueName 队列名
* @param AsyncCallback|null $callback
*/
public function deleteQueueAsync($queueName, AsyncCallback $callback = NULL)
public function deleteQueueAsync($queueName, AsyncCallback $callback = null)
{
try {
$this->client->deleteQueueAsync($queueName, $callback);
Expand Down
22 changes: 18 additions & 4 deletions src/Connectors/MnsConnector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
*
* This file is part of the milkmeowo/laravel-mns.
*
* (c) Milkmeowo <[email protected]>
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Milkmeowo\LaravelMns\Connectors;

use AliyunMNS\Client as MnsClient;
Expand All @@ -10,9 +22,10 @@
class MnsConnector implements ConnectorInterface
{
/**
* 接口方法,连接器
* 接口方法,连接器.
*
* @param array $config
*
* @return \Illuminate\Contracts\Queue\Queue|MnsQueue
*/
public function connect(array $config)
Expand All @@ -23,23 +36,24 @@ public function connect(array $config)
}

/**
* Mns 适配器
* Mns 适配器.
*
* @param array $config
*
* @return MnsAdapter
*/
public function getAdapter(array $config)
{
$client = $this->getClient($config);

return new MnsAdapter($client, $config['queue']);

}

/**
* Mns Client
* Mns Client.
*
* @param array $config
*
* @return MnsClient
*/
public function getClient(array $config)
Expand Down
16 changes: 14 additions & 2 deletions src/Console/MnsCreateQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

namespace Milkmeowo\LaravelMns\Console;
/*
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
*
* This file is part of the milkmeowo/laravel-mns.
*
* (c) Milkmeowo <[email protected]>
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Milkmeowo\LaravelMns\Console;

use AliyunMNS\Client;
use AliyunMNS\Exception\MnsException;
Expand Down Expand Up @@ -36,14 +47,15 @@ public function handle()
if (!$queue) {
$queue = $this->ask('请输入队列名称');
}

try {
$client = new Client($config['endpoint'], $config['key'], $config['secret']);
$request = new CreateQueueRequest($queue);
$client->createQueue($request);
$this->info('队列创建成功');
$this->alert($queue);
} catch (MnsException $e) {
$this->error('队列创建失败:' . $e);
$this->error('队列创建失败:'.$e);
}
}
}
15 changes: 14 additions & 1 deletion src/Console/MnsDeleteQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
*
* This file is part of the milkmeowo/laravel-mns.
*
* (c) Milkmeowo <[email protected]>
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Milkmeowo\LaravelMns\Console;

use AliyunMNS\Client;
Expand Down Expand Up @@ -34,13 +46,14 @@ public function handle()
if (!$queue) {
$queue = $this->ask('请输入队列名称');
}

try {
$client = new Client($config['endpoint'], $config['key'], $config['secret']);
$client->deleteQueue($queue);
$this->info('队列删除成功');
$this->alert($queue);
} catch (MnsException $e) {
$this->error('队列删除失败:' . $e);
$this->error('队列删除失败:'.$e);
}
}
}
17 changes: 15 additions & 2 deletions src/Console/MnsFlushCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
*
* This file is part of the milkmeowo/laravel-mns.
*
* (c) Milkmeowo <[email protected]>
* @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Milkmeowo\LaravelMns\Console;

use AliyunMNS\Client;
Expand Down Expand Up @@ -41,6 +53,7 @@ public function handle()
$hasMessage = true;
while ($hasMessage) {
$this->info('拉取信息中...');

try {
$response = $queue->batchPeekMessage(15);
if ($response->getMessages()) {
Expand All @@ -55,15 +68,15 @@ public function handle()
$response = $queue->batchReceiveMessage(new BatchReceiveMessageRequest(15, 30));
$handles = [];
/**
* @var Message $message
* @var Message
*/
foreach ($response->getMessages() as $message) {
$handles[] = $message->getReceiptHandle();
}
$response = $queue->batchDeleteMessage($handles);
if ($response->isSucceed()) {
foreach ($handles as $handle) {
$this->info(sprintf("信息: %s 删除成功", $handle));
$this->info(sprintf('信息: %s 删除成功', $handle));
}
}
}
Expand Down
Loading

0 comments on commit 759a404

Please sign in to comment.