Sending Messages
Sending a message using a Pod is as simple as calling Send(msg). The only required field is the message type, which is analogous to a topic or subject in other messaging systems. Messages have a few other properties that can be taken advantage of, which will be discussed in a future section.
1
package main
2
3
import (
4
"encoding/json"
5
6
"github.com/suborbital/grav/grav"
7
)
8
9
type heartbeat struct {
10
Healthy bool `json:"healthy"`
11
}
12
13
func sending() {
14
g := grav.New()
15
16
heart := heartbeat{Healthy: true}
17
msg := grav.NewMsg(grav.MsgTypeDefault, heart.JSON())
18
19
p := g.Connect()
20
p.Send(msg)
21
}
22
23
func (h *heartbeat) JSON() []byte {
24
bytes, _ := json.Marshal(h)
25
return bytes
26
}
27
Copied!
Last modified 1yr ago
Copy link