Last active
October 12, 2016 13:52
-
-
Save koolhead17/7f538d48c2f87390333a1d38f9bb6479 to your computer and use it in GitHub Desktop.
go program to listen to nats event notification.
This file contains hidden or 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 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