47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"runtime"
|
|
|
|
"git.mziesel.nl/mans/zadmin/internal/models"
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
func main() {
|
|
nc, err := nats.Connect(nats.DefaultURL)
|
|
|
|
if err != nil {
|
|
log.Fatalf("failed to connect to nats-server: %s\n", err)
|
|
}
|
|
|
|
log.Println("connected to nats-server")
|
|
|
|
// simply print to the console for now
|
|
nc.Subscribe(".", func(msg *nats.Msg) {
|
|
log.Printf("Msg received on [%s] : %s\n", msg.Subject, string(msg.Data))
|
|
})
|
|
nc.Subscribe("client/disconnected", func(msg *nats.Msg) {
|
|
log.Printf("Msg received on [%s] : %s\n", msg.Subject, string(msg.Data))
|
|
})
|
|
nc.Subscribe("client/connected", func(msg *nats.Msg) {
|
|
log.Printf("Msg received on [%s] : %s\n", msg.Subject, string(msg.Data))
|
|
})
|
|
nc.Subscribe("client/machinedata", func(msg *nats.Msg) {
|
|
data := models.Machine{}
|
|
err = json.Unmarshal(msg.Data, &data)
|
|
if err != nil {
|
|
log.Println("failed to Unmarshal Machine: ", err)
|
|
} else {
|
|
log.Printf("Msg received on [%s]: %s\n", msg.Subject, models.PrettyFormatData(data))
|
|
}
|
|
})
|
|
|
|
// shouldExit := false
|
|
// for !shouldExit {
|
|
// }
|
|
// keep running indefenitly
|
|
runtime.Goexit()
|
|
}
|