Last active
September 11, 2020 22:57
-
-
Save csthompson/2df847d37b7268cd6759095686c702e7 to your computer and use it in GitHub Desktop.
NATS Publisher
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 ( | |
"log" | |
"time" | |
nats "github.com/nats-io/nats.go" | |
) | |
type Msg struct { | |
Subject string | |
Body []byte | |
} | |
func main() { | |
nc, _ := nats.Connect(nats.DefaultURL) | |
ec, _ := nats.NewEncodedConn(nc, nats.JSON_ENCODER) | |
msg := Msg{ | |
Subject: "Hello World", | |
Body: []byte("Hello!"), | |
} | |
log.Println("Running publisher") | |
for { | |
ec.Publish("heartbeat", msg) | |
time.Sleep(time.Second * 5) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment