Skip to content

Commit d365e82

Browse files
committed
First commit
0 parents  commit d365e82

16 files changed

+999
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitignore

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

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
3+
php:
4+
- '7.1'
5+
- '7.2'
6+
7+
before_script:
8+
- travis_retry composer self-update
9+
- travis_retry composer update --no-interaction --prefer-source
10+
11+
script: vendor/bin/phpunit --coverage-text

LICENSE

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

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Laravel PubSub Queue
2+
3+
[![Travis](https://img.shields.io/travis/kainxspirits/laravel-pubsub-queue.svg)](https://github.com/kainxspirits/laravel-pubsub-queue)
4+
[![StyleCI](https://styleci.io/repos//shield)](https://styleci.io/repos/)
5+
6+
This package is a Laravel queue driver that use the [Google PubSub](https://github.com/GoogleCloudPlatform/google-cloud-php-pubsub) service.
7+
8+
## Installation
9+
10+
You can easily install this package with [Composer](https://getcomposer.org) by running this command :
11+
12+
```bash
13+
composer require kainxspirits/laravel-pubsub-queue
14+
```
15+
16+
If you disabled package discovery, you can still manually register this package by adding the following line to the providers of your `config/app.php` file :
17+
18+
```php
19+
Kainxspirits\PubSubQueue\PubSubQueueServiceProvider::class,
20+
```
21+
22+
## Configuration
23+
24+
Add a `pubsub` connection to your `config/queue.php` file. From there, you can use any configuration values from the original pubsub client. Just make sure to use snake_case for the keys name.
25+
26+
You can check [Google Cloud PubSub client](http://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.62.0/pubsub/pubsubclient?method=__construct) for more details about the different options.
27+
28+
```php
29+
'pubsub' => [
30+
'driver' => 'pubsub',
31+
'queue' => env('PUBSUB_QUEUE', 'default'),
32+
'project_id' => env('PUBSUB_PROJECT_ID', 'your-project-id'),
33+
'retries' => 3,
34+
'request_timeout' => 60
35+
],
36+
```
37+
38+
## Testing
39+
40+
You can run the tests with :
41+
42+
```bash
43+
vendor/bin/phpunit
44+
```
45+
46+
## License
47+
48+
This project is licensed under the terms of the MIT license. See [License File](LICENSE) for more information.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

composer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "kainxspirits/laravel-pubsub-queue",
3+
"description": "Queue driver for Google Cloud Pub/Sub.",
4+
"keywords": [
5+
"kainxspirits",
6+
"laravel",
7+
"queue",
8+
"gcp",
9+
"google",
10+
"pubsub"
11+
],
12+
"license": "MIT",
13+
"type": "library",
14+
"authors": [
15+
{
16+
"name": "Kendryck",
17+
"email": "kainxspirits@users.noreply.github.com"
18+
}
19+
],
20+
"require": {
21+
"php" : ">=7.1",
22+
"illuminate/queue": "^5.6",
23+
"google/cloud-pubsub": "^1.1"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^7.1"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Kainxspirits\\PubSubQueue\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Kainxspirits\\PubSubQueue\\Tests\\": "tests/"
36+
}
37+
},
38+
"scripts": {
39+
"test": "vendor/bin/phpunit"
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"Kainxspirits\\PubSubQueue\\PubSubQueueServiceProvider"
45+
]
46+
}
47+
},
48+
"minimum-stability": "stable"
49+
}

phpunit.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
verbose="true">
12+
<testsuites>
13+
<testsuite name="tests">
14+
<directory suffix="Tests.php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

src/Connectors/PubSubConnector.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Kainxspirits\PubSubQueue\Connectors;
4+
5+
use Google\Cloud\PubSub\PubSubClient;
6+
use Kainxspirits\PubSubQueue\PubSubQueue;
7+
use Illuminate\Queue\Connectors\ConnectorInterface;
8+
9+
class PubSubConnector implements ConnectorInterface
10+
{
11+
/**
12+
* Default queue name.
13+
*
14+
* @var string
15+
*/
16+
protected $default_queue = 'default';
17+
18+
/**
19+
* Establish a queue connection.
20+
*
21+
* @param array $config
22+
* @return \Illuminate\Contracts\Queue\Queue
23+
*/
24+
public function connect(array $config)
25+
{
26+
$gcp_config = $this->transformConfig($config);
27+
28+
return new PubSubQueue(
29+
new PubSubClient($gcp_config),
30+
$config['queue'] ?? $this->default_queue
31+
);
32+
}
33+
34+
/**
35+
* Transform the config to key => value array.
36+
*
37+
* @param array $config
38+
*
39+
* @return array
40+
*/
41+
protected function transformConfig($config)
42+
{
43+
return array_reduce(array_map([$this, 'transformConfigKeys'], $config, array_keys($config)), function ($carry, $item) {
44+
$carry[$item[0]] = $item[1];
45+
46+
return $carry;
47+
}, []);
48+
}
49+
50+
/**
51+
* Transform the keys of config to camelCase.
52+
*
53+
* @param string $item
54+
* @param string $key
55+
*
56+
* @return array
57+
*/
58+
protected function transformConfigKeys($item, $key)
59+
{
60+
return [camel_case($key), $item];
61+
}
62+
}

0 commit comments

Comments
 (0)