Skip to content

Instantly share code, notes, and snippets.

@Jofre
Created August 17, 2018 14:13
Show Gist options
  • Save Jofre/abe2c55b026d0c8af3e3f719b82a0e57 to your computer and use it in GitHub Desktop.
Save Jofre/abe2c55b026d0c8af3e3f719b82a0e57 to your computer and use it in GitHub Desktop.
package main
import (
"cloud.google.com/go/pubsub"
"context"
"net/http"
)
const (
projectId = "<PROJECT_ID>"
topicId = "<TOPIC_ID>"
subscriptionId = "<SUBSCRIPTION_ID>"
)
func main() {
// Reply to GAE healthchecks
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {})
go http.ListenAndServe(":8080", nil)
// Start a process pulling messages
ctx := context.Background()
client, _ := pubsub.NewClient(ctx, projectId)
sub := client.Subscription(subscriptionId)
_ = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
go func(m *pubsub.Message) {
// Handle the message here
m.Ack()
}(m)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment