Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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 2 months ago
JSON representation

Google Cloud Platform Pub/Sub python toolbox

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")
```