title: Caching connection for ActiveMQ using Go-Stomp
body: <p>Using Go-Stomp, one can obtain the connection using below code.</p>
  
  <pre><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))
      }
  </code></pre>
  
  <p>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? <br>Later sounds in-efficient.<br>
  <strong>Send</strong> 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? <strong>Conn</strong> struct has <strong>closed</strong> member but this is not exposed via any method.</p>
  
  <pre><code>// 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
  }
  </code></pre>