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") } 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) 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