Search code examples
goactivemq-classicstompamazon-mq

Connect to ActiveMQ via STOMP in Go


Trying to connect to ActiveMQ instance on AWS via github.com/go-stomp/stomp library.

The following code throws invalid command error:

func (s *STOMP) Init() error {
    netConn, err := stomp.Dial("tcp", "host:61614")
    if err != nil {
        return errors.Wrap(err, "dial to server")
    }

    s.conn = netConn

    return nil
}

Solution

  • AmazonMQ uses stomp+ssl proto, so the proper way to connect to it is to setup TLS connection on your own first:

    func (s *STOMP) Init() error {
        netConn, err := tls.Dial("tcp", "host:61614", &tls.Config{})
        if err != nil {
            return errors.Wrap(err, "dial tls")
        }
        stompConn, err := stomp.Connect(netConn)
        if err != nil {
            return errors.Wrap(err, "dial to server")
        }
    
        s.conn = stompConn
    
        return nil
    }
    

    https://github.com/go-stomp/stomp/wiki/Connect-using-TLS