timetable-mgr/vstp/subscribe.go

40 lines
896 B
Go
Raw Normal View History

2023-07-19 21:31:00 +01:00
package vstp
import (
"time"
"git.fjla.uk/owlboard/timetable-mgr/log"
"git.fjla.uk/owlboard/timetable-mgr/messaging"
2023-07-19 21:31:00 +01:00
"github.com/go-stomp/stomp/v3"
)
func Subscribe() {
sub, err := messaging.Client.Subscribe("/topic/VSTP_ALL", stomp.AckAuto)
if err != nil {
log.Msg.Fatal("Unable to start subscription: " + err.Error())
}
log.Msg.Info("Subscription to VSTP topic successful, listening")
go func() {
log.Msg.Debug("GOROUTINE: VSTP Message Handler Started")
defer func() {
if r := recover(); r != nil {
log.Msg.Warn("GOROUTINE: VSTP Message Handler Stopped")
time.Sleep(time.Second * 10)
log.Msg.Fatal("GOROUTINE: VSTP Message Handler Failed")
}
}()
2023-07-19 21:31:00 +01:00
for {
msg := <-sub.C
if msg.Err != nil {
2023-07-21 10:02:55 +01:00
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
2023-07-19 21:31:00 +01:00
} else {
log.Msg.Info("STOMP Message Received")
2023-07-19 21:31:00 +01:00
handle(msg)
}
}
}()
select {}
}