2023-07-19 21:31:00 +01:00
|
|
|
package vstp
|
|
|
|
|
|
|
|
import (
|
2023-07-21 12:12:16 +01:00
|
|
|
"time"
|
|
|
|
|
2024-03-25 11:26:07 +00:00
|
|
|
"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 {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Fatal("Unable to start subscription: " + err.Error())
|
2023-07-19 21:31:00 +01:00
|
|
|
}
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Info("Subscription to VSTP topic successful, listening")
|
2023-07-19 21:31:00 +01:00
|
|
|
|
|
|
|
go func() {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Debug("GOROUTINE: VSTP Message Handler Started")
|
2023-07-21 12:12:16 +01:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Warn("GOROUTINE: VSTP Message Handler Stopped")
|
2023-07-21 12:12:16 +01:00
|
|
|
time.Sleep(time.Second * 10)
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Fatal("GOROUTINE: VSTP Message Handler Failed")
|
2023-07-21 12:12:16 +01:00
|
|
|
}
|
|
|
|
}()
|
2023-07-19 21:31:00 +01:00
|
|
|
for {
|
|
|
|
msg := <-sub.C
|
|
|
|
if msg.Err != nil {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Error("STOMP Message Error: " + msg.Err.Error())
|
2023-07-19 21:31:00 +01:00
|
|
|
} else {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Info("STOMP Message Received")
|
2023-07-19 21:31:00 +01:00
|
|
|
handle(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {}
|
|
|
|
}
|