Using Go-Stomp, one can obtain the connection using below code.
if conn, err = stomp.Dial("tcp",
Broker.URI,
stomp.ConnOpt.Login(Broker.User, Broker.Password)); err != nil {
panic(fmt.Sprintf("Could not connect to ActiveMQ using brokerUri %v. Can not continue.", Broker.URI))
}
Can the connection be cached to reuse to send messages for different requests?
Or do we need to obtain the connection each time one wants to send a message?
Later sounds in-efficient.
Send method on the connection instance closes the connection in case of failures. So if we cache it, one has to check if the connection is still live for subsequent send message invocations. But I did not find a method to check if the connection is closed? Conn struct has closed member but this is not exposed via any method.
// A Conn is a connection to a STOMP server. Create a Conn using either
// the Dial or Connect function.
type Conn struct {
conn io.ReadWriteCloser
readCh chan *frame.Frame
writeCh chan writeRequest
version Version
session string
server string
readTimeout time.Duration
writeTimeout time.Duration
closed bool
options *connOptions
}