Created
August 17, 2018 14:13
-
-
Save Jofre/abe2c55b026d0c8af3e3f719b82a0e57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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