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