package messaging import ( "os" "git.fjla.uk/owlboard/mq-client/log" "go.uber.org/zap" "github.com/go-stomp/stomp/v3" ) type nrodCredential struct { user string pass string } func getCredentials() nrodCredential { var nrod_user string = os.Getenv("OWL_LDB_CORPUSUSER") var nrod_pass string = os.Getenv("OWL_LDB_CORPUSPASS") if nrod_user == "" || nrod_pass == "" { log.Msg.Fatal("No NROD Credentials provided") } log.Msg.Debug("NROD Credentials loaded for user: " + nrod_user) return nrodCredential{ user: nrod_user, pass: nrod_pass, } } var client = dial() func dial() *stomp.Conn { var credentials nrodCredential = getCredentials() conn, err := stomp.Dial("tcp", "publicdatafeeds.networkrail.co.uk:61618", stomp.ConnOpt.Login(credentials.user, credentials.pass), stomp.ConnOpt.HeartBeat(15000, 15000), stomp.ConnOpt.Header("client-id", credentials.user), ) if err != nil { log.Msg.Fatal("Unable to connect to STOMP Client", zap.String("err", err.Error())) } //defer disconnect(conn) // This exits as soon as the function has returned log.Msg.Info("Initialised STOMP Client") return conn } func disconnect(conn *stomp.Conn) { if conn != nil { err := conn.Disconnect() if err != nil { conn.MustDisconnect() } } } // Register against the MQ Server and log each message for testing purposes