Skip to content

Commit ed96e9a

Browse files
committed
Add Aliyun Mns Driver For Laravel Queue
0 parents  commit ed96e9a

File tree

121 files changed

+8450
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+8450
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
.DS_Store
3+
vendor
4+
composer.lock

.styleci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
preset: psr2
2+
3+
enabled:
4+
- length_ordered_imports
5+
6+
finder:
7+
exclude:
8+
- "lib"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Laravel-MNS
2+
3+
Laravel 队列的阿里云消息服务(MNS)驱动。
4+
5+
## 安装
6+
7+
```bash
8+
composer require milkmeowo/laravel-mns
9+
```
10+
11+
## 配置
12+
13+
1.在 config/app.php 注册 ServiceProvider(Laravel 5.5 无需手动注册)
14+
15+
```php
16+
'providers' => [
17+
// ...
18+
Milkmeowo\LaravelMns\LaravelMnsServiceProvider::class,
19+
],
20+
```
21+
22+
2.在 `config/queue.php` 中增加 `mns` 配置:
23+
24+
```php
25+
'connections' => [
26+
'redis' => [
27+
'driver' => 'redis',
28+
'connection' => 'default',
29+
'queue' => 'default',
30+
'expire' => 60,
31+
],
32+
// 新增阿里云 MNS。
33+
'mns' => [
34+
'driver' => 'mns',
35+
'key' => env('QUEUE_MNS_ACCESS_KEY', ''),
36+
'secret' => env('QUEUE_MNS_SECRET_KEY', ''),
37+
'endpoint' => env('QUEUE_MNS_ENDPOINT', ''),
38+
'queue' => env('QUEUE_NAME',''),
39+
'wait_seconds' => env('QUEUE_WAIT_SECONDS', 30),
40+
],
41+
],
42+
```
43+
44+
3.在 `.env` 增加
45+
46+
```bash
47+
QUEUE_DRIVER=mns
48+
QUEUE_NAME=your_queue_name
49+
QUEUE_MNS_ACCESS_KEY=your_acccess_key
50+
QUEUE_MNS_SECRET_KEY=your_secret_key
51+
QUEUE_MNS_ENDPOINT=your-endpoint
52+
# 关于 wait_seconds 可以看 https://help.aliyun.com/document_detail/35136.html
53+
QUEUE_WAIT_SECONDS=30
54+
```
55+
56+
## 使用
57+
58+
正常使用 Laravel Queue 即可:
59+
60+
* [Laravel 队列服务(官方英文文档)](https://laravel.com/docs/5.6/queues)
61+
62+
* [Laravel 队列服务(中文文档)](https://laravel-china.org/docs/laravel/5.6/queues/1395)
63+
64+
## 命令
65+
66+
### 列出所有队列
67+
68+
```bash
69+
php artisan queue:mns:list
70+
// 例如
71+
php artisan queue:mns:list
72+
// 输入队列名以 prefix 开头的队列
73+
php artisan queue:mns:list -p
74+
75+
# 请填写prefix:
76+
# >
77+
78+
```
79+
80+
### 增加队列
81+
82+
```bash
83+
php artisan queue:mns:create 队列名
84+
// 例如
85+
php artisan queue:mns:create wechat-notify
86+
```
87+
88+
### 删除队列
89+
90+
```bash
91+
php artisan queue:mns:delete 队列名
92+
// 例如
93+
php artisan queue:mns:delete wechat-notify
94+
```
95+
96+
### 显示队列内容
97+
98+
```bash
99+
php artisan queue:mns:show 队列名
100+
// 例如
101+
php artisan queue:mns:show wechat-notify
102+
```
103+
104+
### 删除队列所有内容
105+
106+
```bash
107+
php artisan queue:mns:flush 队列名
108+
// 例如
109+
php artisan queue:mns:flush wechat-notify
110+
```
111+
112+
## 测试
113+
114+
``` bash
115+
$ composer test
116+
```
117+
118+
## 参考
119+
120+
- [abrahamgreyson/laravel-mns](https://github.com/abrahamgreyson/laravel-mns)
121+
122+
## 许可
123+
124+
MIT

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "milkmeowo/laravel-mns",
3+
"description": "Aliyun Mns Driver For Laravel Queue",
4+
"keywords": ["aliyun", "laravel", "queue", "mns"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "milkmeowo",
9+
"email": "milkmeowo@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"illuminate/queue": "^5.6",
14+
"guzzlehttp/guzzle": "^6.3"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^7.1",
18+
"mockery/mockery": "^1.1"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"AliyunMNS\\": "lib/AliyunMNS/",
23+
"Milkmeowo\\LaravelMns\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Milkmeowo\\LaravelMns\\Test\\": "tests/"
29+
}
30+
},
31+
"scripts": {
32+
"test": "phpunit"
33+
},
34+
"extra": {
35+
"laravel": {
36+
"providers": [
37+
"Milkmeowo\\LaravelMns\\LaravelMnsServiceProvider"
38+
]
39+
}
40+
}
41+
}

lib/AliyunMNS/AsyncCallback.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
namespace AliyunMNS;
3+
4+
use AliyunMNS\Exception\MnsException;
5+
use AliyunMNS\Responses\BaseResponse;
6+
7+
class AsyncCallback
8+
{
9+
protected $succeedCallback;
10+
protected $failedCallback;
11+
12+
public function __construct(callable $succeedCallback, callable $failedCallback)
13+
{
14+
$this->succeedCallback = $succeedCallback;
15+
$this->failedCallback = $failedCallback;
16+
}
17+
18+
public function onSucceed(BaseResponse $result)
19+
{
20+
return call_user_func($this->succeedCallback, $result);
21+
}
22+
23+
public function onFailed(MnsException $e)
24+
{
25+
return call_user_func($this->failedCallback, $e);
26+
}
27+
}
28+
29+
?>

0 commit comments

Comments
 (0)