Skip to content

Instantly share code, notes, and snippets.

@trennepohl
Created September 22, 2019 09:28
Show Gist options
  • Save trennepohl/b2787ec30073d7fc0bed2c8183dce51b to your computer and use it in GitHub Desktop.
Save trennepohl/b2787ec30073d7fc0bed2c8183dce51b to your computer and use it in GitHub Desktop.
Subscribe all messages
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