28 lines
418 B
Go
28 lines
418 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
func main() {
|
|
nc, err := nats.Connect(nats.DefaultURL)
|
|
defer nc.Close()
|
|
if nil != err {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
for {
|
|
m, err := nc.Request("foo", []byte("Hello Request!"), 1*time.Second)
|
|
if nil != err {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Printf("Received a Response: %s\n", string(m.Data))
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
}
|