Search code examples
sslssl-certificateclientamqpactivemq-artemis

Cannot connect to ActiveMQ Artemis with AMQP 0.9.1 client


I am trying to connect to an ActiveMQ Artemis broker with an AMQP 0.9.1 Go client, but there are some problems I can't figure out.

This is my client code:

package main

import (
    "fmt"
    "log"

    "github.com/streadway/amqp"
)

func main() {
    brokerURL := "amqp://admin:admin@10.37.129.2:61616" // Update with your broker URL
    queueName := "amqp/message"

    // Create an AMQP connection with the custom TLS configuration
    conn, err := amqp.Dial(brokerURL)
    if err != nil {
        log.Fatalf("Failed to connect to: %v", err)
    }
    defer conn.Close()

    ch, err := conn.Channel()
    if err != nil {
        log.Fatalf("Failed to open a channel: %v", err)
    }
    defer ch.Close()

    q, err := ch.QueueDeclare(
        queueName, // name
        false,     // durable
        false,     // delete when unused
        false,     // exclusive
        false,     // no-wait
        nil,       // arguments
    )
    if err != nil {
        log.Fatalf("Failed to declare a queue: %v", err)
    }

    body := "Hello, Artemis AMQP!"
    err = ch.Publish(
        "",     // exchange
        q.Name, // routing key
        false,  // mandatory
        false,  // immediate
        amqp.Publishing{
            ContentType: "text/plain",
            Body:        []byte(body),
        })
    if err != nil {
        log.Fatalf("Failed to publish a message: %v", err)
    }

    fmt.Println("Message sent successfully.")
}

In my broker.xml there is no SSL configs, but I am getting SSL certificate error. With STOMP I can connect to ActiveMQ Artemis with Dial(), but AMQP is not working.

conn, err = stomp.Dial("tcp", addr, stomp.ConnOpt.Login(username, password))

When I run AMQP client code I am getting this error

Failed to connect to: Exception (501) Reason: "Exception (501) Reason: \"frame could not be parsed\""
exit status 1

On the server side I am getting the following error:

832 WARN  [org.apache.activemq.artemis.core.server] AMQ222216: Security problem while authenticating: AMQ229031: Unable to validate user from null. Username: null; SSL certificate subject DN: unavailable

I want to connect to the server without needing an SSL configuration.

Here's my broker.xml:

<connectors>
    <connector name="artemis">tcp://10.37.129.2:61616</connector>   
 </connectors>

<acceptors>
<acceptor name="artemis">tcp://10.37.129.2:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;supportAdvisory=false;suppressInternalManagementObjects=false</acceptor> 
</acceptors>

<cluster-user>admin</cluster-user>
<cluster-password>admin</cluster-password>


 <!--    Clustering configuration  -->
  <broadcast-groups>
     <broadcast-group name="bg-group1">
        <group-address>${udp-address:231.7.7.7}</group-address>
        <group-port>9876</group-port>
        <broadcast-period>100</broadcast-period>
        <connector-ref>artemis</connector-ref>
     </broadcast-group>
  </broadcast-groups>

  <discovery-groups>
     <discovery-group name="dg-group1"> 
        <group-address>${udp-address:231.7.7.7}</group-address>
        <group-port>9876</group-port>
        <refresh-timeout>10000</refresh-timeout>
     </discovery-group>
  </discovery-groups>

  <cluster-connections>
     <cluster-connection name="my-cluster">
        <address>jms</address>
        <connector-ref>artemis</connector-ref>
        <retry-interval>500</retry-interval>
        <use-duplicate-detection>true</use-duplicate-detection>
        <message-load-balancing>ON_DEMAND</message-load-balancing>
        <max-hops>1</max-hops>
        <static-connectors>
           <connector-ref>artemis</connector-ref>
        </static-connectors>
     </cluster-connection>
  </cluster-connections>

<ha-policy>
     <replication>
        <master>
           <!-- Configure other replication settings as needed -->
           <check-for-live-server>true</check-for-live-server>
        </master>
     </replication>
  </ha-policy>



  <security-settings>
     <security-setting match="#">
        <permission type="createNonDurableQueue" roles="amq"/>
        <permission type="deleteNonDurableQueue" roles="amq"/>
        <permission type="createDurableQueue" roles="amq"/>
        <permission type="deleteDurableQueue" roles="amq"/>
        <permission type="createAddress" roles="amq"/>
        <permission type="deleteAddress" roles="amq"/>
        <permission type="consume" roles="amq"/>
        <permission type="browse" roles="amq"/>
        <permission type="send" roles="amq"/>
        <!-- we need this otherwise ./artemis data imp wouldn't work -->
        <permission type="manage" roles="amq"/>
     </security-setting>
  </security-settings>

Solution

  • Looking at the sample code it seems that the client is this one "github.com/streadway/amqp" which is coming from here "https://github.com/streadway/amqp" which appears to be a defunct fork of the RabbitMQ AMQP 0.9.1 client.

    Since the Artemis broker is an AMQP 1.0 broker it is not surprising that the connection attempt from an unsupported version of the protocol client is triggering confusing errors. My first suggestion then would be to switch to an AMQP 1.0 client as that would be the most immediate thing to fix, then you could work from there to resolve any additional errors.