Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Last active June 3, 2020 12:30
Show Gist options
  • Save ripienaar/080b491b0a014214c5682737953df4bc to your computer and use it in GitHub Desktop.
Save ripienaar/080b491b0a014214c5682737953df4bc to your computer and use it in GitHub Desktop.
msg := nats.NewMsg("subject")
msg.Data = []byte("hello world")
msg.Header.Add("X-Hello", "World")
nc.PublishMsg(msg)
seq := 0
nc.Subscribe("subject", func(m *nats.Msg) {
fmt.Printf("Payload: %q\n", m.Data)
for h, vals := range m.Header {
for _, val := range vals {
fmt.Printf("%s: %s", h, val)
}
}
msg := nats.NewMsg(m.Reply)
msg.Data = []byte("+OK")
msg.Header.Add("X-Sequence", strconv.Itoa(seq))
m.RespondMsg(msg)
seq++
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment