Search code examples
activemq-classicamqpspring-amqp

Apache ActiveMQ AMQP Spring Boot AWS


I have an ActiveMQ AWS service with protocol AMQP. AWS returns to me:

failover:(amqp+ssl://b-ca138bd4-e6c4-4596-8329-f11bebf40111-1.mq.us-east-1.amazonaws.com:5671,amqp+ssl://b-ca138bd4-e6c4-4596-8329-f11bebf40111-2.mq.us-east-1.amazonaws.com:5671)

I am trying to implement using Spring Boot the connection with that endpoint, but I have many problems. I have tried with many ways, but I can't connect to the ActiveMQ using Spring.

I have tried:

Creating many configuration Beans, like:

@Bean
fun connectionFactory(): ConnectionFactory {
    val activeMQConnectionFactory = ActiveMQConnectionFactory()
    activeMQConnectionFactory.brokerURL = "amqp+ssl://b-ca138bd4-e6c4-4596-8329-f11bebf40111-1.mq.us-east-1.amazonaws.com:5671"
    activeMQConnectionFactory.trustedPackages = listOf("com.rappi.scaffolding")
    return activeMQConnectionFactory
}

and using many dependencies like:

implementation("org.apache.activemq:activemq-spring:5.17.0")
implementation("org.springframework:spring-jms")

and

implementation("org.springframework.boot:spring-boot-starter-artemis")

But is not possible for me establish the connection. At this moment I am seeing this error:

Reason: java.io.IOException: Transport scheme NOT recognized: [amqp+ssl]

There are some example in Java or Kotlin or guide to connect me with AWS using AMQP protocol? I didn't find any in Google.

I have read that using QPid, but it not works for me.

I have found many examples using Rabbit, but not Apache ActiveMQ protocol amqp+ssl.

Finally It works using the Bean:

@Bean
    fun connectionFactory(): ConnectionFactory {
        return JmsConnectionFactory(
            "failover:(amqps://b-ca138bd4-e6c4-4596-8329-f11bebf40111-1.mq.us-east-1.amazonaws.com:5671,amqps://b-ca138bd4-e6c4-4596-8329-f11bebf40111-2.mq.us-east-1.amazonaws.com:5671)").apply {
            this.username = user
            this.password = passwordAQ
        }

Solution

  • There are many things wrong with your code and configuration.

    First, the URL you're using for your client is incorrect. The amqp+ssl scheme is not valid for any client. That's the scheme used to define the connector in the ActiveMQ broker configuration.

    Second, your dependencies are wrong. As far as the client goes you just need:

    implementation("org.apache.qpid:qpid-jms-client:1.6.0")
    

    Of course, if you're using Spring you'll need all the related Spring dependencies, but as far as the client itself goes this is all you need.

    Third, your code is wrong. You should be using something like this:

    @Bean
    fun connectionFactory(): ConnectionFactory {
        return new org.apache.qpid.jms.JmsConnectionFactory("failover:(amqps://b-ca138bd4-e6c4-4596-8329-f11bebf40111-1.mq.us-east-1.amazonaws.com:5671,amqps://b-ca138bd4-e6c4-4596-8329-f11bebf40111-2.mq.us-east-1.amazonaws.com:5671)");
    }