mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-09-19 10:34:53 +02:00
initial import
This commit is contained in:
29
microservices/nats/receiver/cmd/main.go
Normal file
29
microservices/nats/receiver/cmd/main.go
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
nc, err := nats.Connect(nats.DefaultURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not connect to server because of %v", err)
|
||||
}
|
||||
defer nc.Close()
|
||||
sub, err := nc.SubscribeSync("foo")
|
||||
if err != nil {
|
||||
log.Fatalf("Could not subscribe because of %v", err)
|
||||
}
|
||||
m, err := sub.NextMsg(20 * time.Second)
|
||||
if m == nil {
|
||||
log.Println("No messages available")
|
||||
return
|
||||
}
|
||||
log.Println(m.Subject)
|
||||
log.Println(string(m.Data))
|
||||
sub.Unsubscribe()
|
||||
sub.Drain()
|
||||
}
|
Reference in New Issue
Block a user