Created
September 22, 2019 09:28
-
-
Save trennepohl/b2787ec30073d7fc0bed2c8183dce51b to your computer and use it in GitHub Desktop.
Subscribe all messages
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 ( | |
"fmt" | |
"time" | |
"github.com/nats-io/stan.go" | |
) | |
func main() { | |
sc, err := stan.Connect("test-cluster", "sub2", stan.NatsURL("localhost:4222")) | |
if err != nil { | |
panic(err.Error()) | |
} | |
sub, _ := sc.Subscribe("novo", func(m *stan.Msg) { | |
fmt.Printf("Received a message: %s\n", string(m.Data)) | |
}, stan.DeliverAllAvailable()) | |
// Close connection | |
time.Sleep(40 * time.Second) | |
sub.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment