https://github.com/pierrekieffer/pubsub-pytoolbox
Google Cloud Platform Pub/Sub python toolbox
https://github.com/pierrekieffer/pubsub-pytoolbox
gcp-pubsub pubsub pubsub-interface pubsub-publisher pubsub-subscriber
Last synced: about 1 year ago
JSON representation
Google Cloud Platform Pub/Sub python toolbox
- Host: GitHub
- URL: https://github.com/pierrekieffer/pubsub-pytoolbox
- Owner: PierreKieffer
- License: bsd-2-clause
- Created: 2020-10-14T08:54:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-14T14:48:07.000Z (over 5 years ago)
- Last Synced: 2023-03-07T01:31:41.813Z (over 3 years ago)
- Topics: gcp-pubsub, pubsub, pubsub-interface, pubsub-publisher, pubsub-subscriber
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pubsub-pytoolbox
Google Cloud Platform Pub/Sub toolbox
## Prerequisities
- GCP project with a Pub/Sub up & running.
- GCP service account and the credential file `private_key.json` associated.
## Install
```bash
pip install .
```
## Usage
### Publisher
```python
import json
from pubsub.op import publisher
data = {"field1" : "value1", "field2" : "value2"}
event = json.dumps(data)
publisher.publish("PROJECT_ID", "TOPIC_ID", "private_key.json", event)
```
### Consumer
Start a background thread to receive messages from Pub/Sub and calls a callback with each message received.
```python
from pubsub.op import consumer
consumer.consume("PROJECT_ID", "SUBSCRIBER_ID", "private_key.json")
```