Compare commits
No commits in common. "fb41485bc5c8ff58c2bda2319062f9ed6441ad7f" and "b42b353c4f90137470ffbd2442f8d6ae34be41d3" have entirely different histories.
fb41485bc5
...
b42b353c4f
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
// "go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate DB Url
|
// Generate DB Url
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package vstp
|
package vstp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
//"git.fjla.uk/owlboard/go-types/pkg/database"
|
||||||
"git.fjla.uk/owlboard/mq-client/log"
|
"git.fjla.uk/owlboard/mq-client/log"
|
||||||
"github.com/go-stomp/stomp/v3"
|
"github.com/go-stomp/stomp/v3"
|
||||||
)
|
)
|
||||||
|
@ -14,4 +18,24 @@ func handle(msg *stomp.Message) {
|
||||||
log.Msg.Info("Messages since started: " + fmt.Sprint(count))
|
log.Msg.Info("Messages since started: " + fmt.Sprint(count))
|
||||||
schedule := unmarshalData(string(msg.Body))
|
schedule := unmarshalData(string(msg.Body))
|
||||||
processEntryType(schedule)
|
processEntryType(schedule)
|
||||||
|
saveToFile(schedule, "transformed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveToFile(msg any, suffix string) {
|
||||||
|
timestamp := time.Now().Format("2006-01-02T15:04:05")
|
||||||
|
path := fmt.Sprintf("message-logs/%s-%s.json", timestamp, suffix)
|
||||||
|
|
||||||
|
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.Debug("Saved message to: " + path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ func unmarshalData(jsonData string) database.Service {
|
||||||
} else if len(schedule.Data.CIFMsg.ScheduleSegment) == 0 {
|
} else if len(schedule.Data.CIFMsg.ScheduleSegment) == 0 {
|
||||||
log.Msg.Warn("ScheduleSegment is empty")
|
log.Msg.Warn("ScheduleSegment is empty")
|
||||||
}
|
}
|
||||||
|
saveToFile(schedule, "unmarshalled") // For Debugging Only
|
||||||
return formatData(&schedule.Data.CIFMsg)
|
return formatData(&schedule.Data.CIFMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ func Subscribe() {
|
||||||
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
|
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Msg.Info("STOMP Message Received")
|
log.Msg.Info("STOMP Message Received")
|
||||||
|
saveToFile(string(msg.Body), "msgBody")
|
||||||
handle(msg)
|
handle(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue