dkx / google-pubsub-subscriber
This package is abandoned and no longer maintained.
No replacement package was suggested.
Symfony console command for Google PubSub
2.2.0
2019-12-18 17:26 UTC
Requires
- php: >=7.3
- google/cloud-pubsub: >=1.18
- nette/utils: >=3.0
- symfony/console: >=4.3
Requires (Dev)
- phpstan/extension-installer: >=1.0
- phpstan/phpstan: >=0.11
- phpstan/phpstan-strict-rules: >=0.11
README
Symfony console command for Google PubSub
Installation
$ composer require dkx/google-pubsub-subscriber
Usage
<?php
use DKX\GooglePubSubSubscriber\SubscriberCommand;
use DKX\GooglePubSubSubscriber\SubscriptionInterface;
use DKX\GooglePubSubSubscriber\SubscriptionsManager;
use Google\Cloud\PubSub\PubSubClient;
use Symfony\Component\Console\Application;
final class TestSubscription implements SubscriptionInterface
{
public function getConsoleName() : string
{
return 'my-test';
}
public function processMessage(array $data) : bool
{
var_dump($data);
return true;
}
}
$client = new PubSubClient();
$manager = new SubscriptionsManager();
$manager->addSubscription(new TestSubscription());
$command = new SubscriberCommand($client, $manager);
$application = new Application();
$application->add($command);
$application->run();
and run:
$ php index.php pubsub:subscribe my-test my-app.prod.test --max-seconds 500 --max-messages 100
my-test
: string returned from your subscription'sgetConsoleName()
methodmy-app.prod.test
: name of existing subscription in Google Cloud Pub/Sub
Standalone usage
<?php
use DKX\GooglePubSubSubscriber\Subscriber;
use Google\Cloud\PubSub\PubSubClient;
$client = new PubSubClient();
$subscriber = new Subscriber($client, 'my-app.prod.test');
$subscriber->setMaxSeconds(500);
$subscriber->setMaxMessages(100);
$subscriber->subscribe(function (array $data): bool {
var_dump($data);
return true;
});