Skip to content

Commit bd0a428

Browse files
authored
Develop (munir131#2)
* Add env var to supress missing credentials warning * Do not delete topic when last message pop * Create subscription before pushin a new job * Do not remove subscriber as it is removed automatically by google * Apply style fix
1 parent 2439c36 commit bd0a428

File tree

10 files changed

+222
-159
lines changed

10 files changed

+222
-159
lines changed

.editorconfig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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
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

.styleci.yml

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

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +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
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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.
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 & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +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/131718560/shield)](https://styleci.io/repos/131718560)
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.
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/131718560/shield)](https://styleci.io/repos/131718560)
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.0

composer.json

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +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-
}
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 & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +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>
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/PubSubQueue.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function pushRaw($payload, $queue = null, array $options = [])
7878
{
7979
$topic = $this->getTopic($queue, true);
8080

81+
$this->subscribeToTopic($topic);
82+
8183
return $topic->publish([
8284
'data' => $payload,
8385
'attributes' => $options,
@@ -131,8 +133,6 @@ public function pop($queue = null)
131133
$this->connectionName,
132134
$queue
133135
);
134-
} else {
135-
$subscription->delete();
136136
}
137137
}
138138

@@ -155,6 +155,8 @@ public function bulk($jobs, $data = '', $queue = null)
155155

156156
$topic = $this->getTopic($queue, true);
157157

158+
$this->subscribeToTopic($topic);
159+
158160
return $topic->publishBatch($payloads);
159161
}
160162

@@ -220,12 +222,29 @@ public function getTopic($queue, $create = false)
220222

221223
if (! $topic->exists() && $create) {
222224
$topic->create();
223-
$topic->subscribe($this->getSubscriberName());
224225
}
225226

226227
return $topic;
227228
}
228229

230+
/**
231+
* Create a new subscription to a topic.
232+
*
233+
* @param \Google\Cloud\PubSub\Topic $topic
234+
*
235+
* @return \Google\Cloud\PubSub\Subscription
236+
*/
237+
public function subscribeToTopic(Topic $topic)
238+
{
239+
$subscription = $topic->subscription($this->getSubscriberName());
240+
241+
if (! $subscription->exists()) {
242+
$subscription = $topic->subscribe($this->getSubscriberName());
243+
}
244+
245+
return $subscription;
246+
}
247+
229248
/**
230249
* Get subscriber name.
231250
*

0 commit comments

Comments
 (0)