2023-07-19 21:31:00 +01:00
|
|
|
package vstp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"time"
|
|
|
|
|
2023-07-20 11:07:39 +01:00
|
|
|
//"git.fjla.uk/owlboard/go-types/pkg/database"
|
2023-07-19 21:31:00 +01:00
|
|
|
"git.fjla.uk/owlboard/mq-client/log"
|
|
|
|
"github.com/go-stomp/stomp/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var count uint64 = 0
|
|
|
|
|
|
|
|
func handle(msg *stomp.Message) {
|
|
|
|
count++
|
|
|
|
log.Msg.Info("Message count: " + fmt.Sprint(count))
|
2023-07-20 11:07:39 +01:00
|
|
|
schedule := unmarshalData(string(msg.Body))
|
2023-07-21 12:12:16 +01:00
|
|
|
processEntryType(schedule)
|
2023-07-20 11:07:39 +01:00
|
|
|
saveToFile(schedule, "transformed")
|
2023-07-19 21:31:00 +01:00
|
|
|
}
|
|
|
|
|
2023-07-20 11:07:39 +01:00
|
|
|
func saveToFile(msg any, suffix string) {
|
2023-07-19 21:31:00 +01:00
|
|
|
timestamp := time.Now().Format("2006-01-02T15:04:05")
|
2023-07-20 11:07:39 +01:00
|
|
|
path := fmt.Sprintf("message-logs/%s-%s.json", timestamp, suffix)
|
2023-07-19 21:31:00 +01:00
|
|
|
|
|
|
|
prettyJSON, err := json.MarshalIndent(msg, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
log.Msg.Error("Error marshaling data to JSON: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(path, prettyJSON, 0644)
|
|
|
|
if err != nil {
|
|
|
|
log.Msg.Error("Error saving message: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Msg.Info("Saved message to: " + path)
|
|
|
|
}
|