Skip to content

Instantly share code, notes, and snippets.

@koolhead17
Last active October 12, 2016 13:52
Show Gist options
  • Save koolhead17/7f538d48c2f87390333a1d38f9bb6479 to your computer and use it in GitHub Desktop.
Save koolhead17/7f538d48c2f87390333a1d38f9bb6479 to your computer and use it in GitHub Desktop.
go program to listen to nats event notification.
package main
// Import Go and NATS packages
import (
"runtime"
"log"
"github.com/nats-io/nats"
)
func main() {
// Create server connection
natsConnection, _ := nats.Connect("nats://yourusername:yoursecret@localhost:4222")
log.Println("Connected")
// Subscribe to subject
log.Printf("Subscribing to subject 'bucketevents'\n")
natsConnection.Subscribe("bucketevents", func(msg *nats.Msg) {
// Handle the message
log.Printf("Received message '%s\n", string(msg.Data) + "'")
})
// Keep the connection alive
runtime.Goexit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment