https://github.com/neutonfoo/go-pubsub
Simple demo for Google Cloud Pub/Sub in Go
https://github.com/neutonfoo/go-pubsub
Last synced: 7 months ago
JSON representation
Simple demo for Google Cloud Pub/Sub in Go
- Host: GitHub
- URL: https://github.com/neutonfoo/go-pubsub
- Owner: neutonfoo
- Created: 2020-05-21T17:23:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-22T00:19:11.000Z (about 6 years ago)
- Last Synced: 2024-04-24T05:52:36.859Z (about 2 years ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Pubsub
Basic implementation of Google Cloud's Pub/Sub in Go. Subscriber consumes 5 messages before exiting.
Based on https://cloud.google.com/pubsub/docs/quickstart-client-libraries
## Set Up
Create Project and enable Pub/Sub API for the project.
Install the Google Cloud SDK `https://cloud.google.com/sdk/docs/quickstart-macos`.
Install the Google Cloud Go Libraries `go get -u cloud.google.com/go/pubsub`.
Create Server Account under Project with roles: "Pub/Sub Publisher" and "Pub/Sub Subscriber". Generate key and save into `keys` folder.
Create topic and subscriber
```sh
# Create topic
gcloud pubsub topics create my-topic
# Create subscriber and subscribe to topic
gcloud pubsub subscriptions create my-sub --topic my-topic
```
## Executing
Open two Terminal windows and export `GOOGLE_APPLICATION_CREDENTIALS` and `PROJECT`.
```sh
cd go-pubsub
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/keys/keys.json
export PROJECT=`gcloud config get-value project`
```
First execute subscriber
```sh
go run subscriber/sub.go
```
Then execute publisher
```sh
go run publisher/pub.go
```