forked from jjeffery/stomp
-
Notifications
You must be signed in to change notification settings - Fork 97
Connect using TLS
Sheran Gunasekera edited this page Mar 27, 2018
·
1 revision
If you ever find yourself in need of connecting to a stomp server over ssl then you will first have to Dial your own TLS connection using the go crypto/tls library.
package main
import (
"crypto/tls"
"log"
"github.com/go-stomp/stomp"
)
var sampleMsg string
const (
hostEndpoint = "stomp.ssl.example.com:61614"
)
func main() {
sampleMsg = `{"id":1234,"name":"sheran","message":"hello world"}`
// Create the TLS Connection first
netConn, err := tls.Dial("tcp", hostEndpoint, &tls.Config{})
if err != nil {
log.Fatalln(err.Error())
}
defer netConn.Close()
// Now create the stomp connection
stompConn, err := stomp.Connect(netConn,
stomp.ConnOpt.Login("username", "password"))
if err != nil {
log.Fatalln(err.Error())
}
defer stompConn.Disconnect()
log.Println(stompConn.Version().String())
}