alldigitalrewards / pubsub
PubSub Message Service
1.1.0
2021-10-04 19:07 UTC
Requires
- php: ^7.0|^8.0
- google/cloud-pubsub: ^1.34
Requires (Dev)
- phpunit/phpunit: ^7.0|^8|^9
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-05 02:13:04 UTC
README
##Usage
##Setup
scenario: Bucket Queue (Topic) to publish messages to Consumer(s) (subscriptions)
Publishing to a Report Queue:
Note: unique names for Topics, i.e. _REPORTS, _TRANSACTION_EMAIL etc.
Create new instance * If Topic and/or Subscription names dont exist they will be created * naming convention is up to you. $projectId = getenv('PROJECT_ID'); //The Google project ID $keyFile = getenv('PUBSUB_KEYFILE'); //The Google project key $messageService = new MessagePublisherService( $projectId, $keyFile );
##Publish
* array of key/value string pairs as many, ex. * throws PubSubServiceException $message = new Message( 'DEV_TESTSERVICE2_TOPIC', 'DEV_TESTSERVICE2_SUBSCRIPTION', ); $messageService->publish( $message, [ 'key1' => $someValue1, //string 'key2' => $someValue2 //string ] );
##Pull Message
* returns array * throws PubSubServiceException $messageConfig = new Message( 'DEV_TESTSERVICE2_TOPIC', 'DEV_TESTSERVICE2_SUBSCRIPTION', ); $message = $messageService->pullMessage($messageConfig) print_r($message['key1']); //$someValue1 print_r($message['key2']); //$someValue2