Last active
March 25, 2020 12:26
-
-
Save ripienaar/e4d4bd43bb328b86b17c027afd817c58 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 ( | |
"context" | |
"fmt" | |
"github.com/nats-io/nats.go" | |
) | |
func main() { | |
nc, err := nats.Connect("localhost") | |
if err != nil { | |
panic(err) | |
} | |
// Subscribe sets up go routines to handle the message and call the | |
// function in the background and returns to your application for | |
// other work | |
nc.Subscribe("demo.hello", func(m *nats.Msg) { | |
fmt.Printf("Received a message: %s\n", string(m.Data)) | |
}) | |
// this is like a super minimal app, so all we do is pause forever | |
// letting the background stuff do their thing | |
<-context.Background().Done() | |
} |
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
% go run sub.go | |
Received a message: test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment