32 lines
730 B
Go
32 lines
730 B
Go
|
package vstp
|
||
|
|
||
|
import (
|
||
|
"git.fjla.uk/owlboard/mq-client/log"
|
||
|
"git.fjla.uk/owlboard/mq-client/messaging"
|
||
|
"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 log.Msg.Warn("GOROUTINE: VSTP Message Handler Stopped")
|
||
|
for {
|
||
|
msg := <-sub.C
|
||
|
if msg.Err != nil {
|
||
|
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
|
||
|
} else {
|
||
|
log.Msg.Debug("STOMP Message Received")
|
||
|
handle(msg)
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
select {}
|
||
|
}
|