Samuel
Samuel

Reputation: 737

Migrating to Spring Boot 3 with ActiveMQ Classic

I am trying to migrate to Spring Boot 3 with the new namespace jakarta instead of javax, but the ActiveMQ Classic client has not been updated and was deprecated. Is there a way to continue using the old ActiveMQ client?

I tried the new ActiveMQ Artemis client but it seems like they are not interoperable with the ActiveMQ Classic server. Including the old ActiveMQ client results in not being able to use JMSTemplate for configuration because JMSTemplate uses jakarta.xx and expects a ConnectionFactory from jakarta.xx not javax.xx

Edit: Didn't work so the only way is to upgrade to ActiveMQ Artemis. That way the codebase is also nearly unchanged.

Edit: April 2023: The new ActiveMQ Client was released. You only need to swap the spring-boot-starter-activemq with the updated version and include this

Upvotes: 17

Views: 23572

Answers (5)

Azdy
Azdy

Reputation: 320

I have JmsTemplate and embedded ActiveMQ in Spring Boot 3.1.2. So I did following steps:

  1. I added this bean to provide embedded ActiveMQ:

      @Bean
      public ConnectionFactory connectionFactory() {
      return new  ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
      }
    
  2. I added these dependencies:

     <dependency>
         <groupId>javax.jms</groupId>
         <artifactId>javax.jms-api</artifactId>
         <version>2.0.1</version>
     </dependency>
    
     <dependency>
         <groupId>org.apache.activemq</groupId>
         <artifactId>activemq-client-jakarta</artifactId>
         <version>5.18.2</version>
     </dependency>
         <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-jms</artifactId>
         <version>6.0.11</version>
     </dependency>
    
         <dependency>
         <groupId>org.apache.activemq</groupId>
         <artifactId>activemq-broker</artifactId>
         <version>5.18.2</version>
         <exclusions>
             <exclusion>
                 <groupId>org.apache.activemq</groupId>
                 <artifactId>activemq-client</artifactId>
             </exclusion>
         </exclusions>
     </dependency>
    
  3. and I removed this:

       <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId> 
       </dependency>
    

Upvotes: 5

wlanger123
wlanger123

Reputation: 86

Jakarta JMS compatible version ActiveMQ 5.18.x has been released. I was able to get this version working with no Spring 5.3.x dependencies:

Removed

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

and included the broker with the new "jakarta client" dependency:

<!-- 5.18 brings initial JMS 2.0 (javax.jms API) and Jakarta Messaging 3.1 (jakarta.jms API) client support -->
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-broker</artifactId>
    <version>5.18.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-client</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-client-jakarta</artifactId>
    <version>5.18.1</version>
</dependency>

We are now again able to send and receive messages with the (not yet migrated) unchanged ActiveMQ installation on our servers - parallel with a Spring Boot 2.7.x application and a 3.0.5 Spring application.

Upvotes: 7

Matt Pavlovich
Matt Pavlovich

Reputation: 4306

To continue to use ActiveMQ 5.x with Spring 3 and Jakarta EE 9, two updates are needed on the ActiveMQ 5.x side-- JMS 2.0 support, and then support for javax.jms -> jakarta.jms namespace change.

The first part is the biggest, and is underway. The ActiveMQ 5.x main branch has preview support for JMS 2.0, and there are plans to provide Jakarta namespace support shortly after.

This is a good page to track JMS 2.0 progress in ActiveMQ 5.x

ref: https://activemq.apache.org/jms2

UPDATE: Apache ActiveMQ 5.18.1 includes a jakarta-enabled client 'activemq-client-jakarta'

Edit: Spring Boot v3 support being added with this change: https://github.com/spring-projects/spring-boot/pull/35048

Upvotes: 5

Bruno Raba&#231;a
Bruno Raba&#231;a

Reputation: 19

While waiting for ActiveMQ update to Jakarta EE 9 i removed

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

And included

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-client</artifactId>
    <version>5.17.3</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>5.3.24</version>
</dependency>

It worked like a charm with Spring Boot 3.0.0

Upvotes: 1

Tim Bish
Tim Bish

Reputation: 18356

As you noticed there is no ActiveMQ client that supports the Jakarta namespace JMS dependency or in fact none that supports JMS 2.0 so you really need to move to something else such as an ActiveMQ Artemis broker and the ActiveMQ Artemis client or Qpid JMS AMQP client v2.1.0 which both support JMS 2.0 and use the Jakarta APIs.

If you are dead set on sticking with ActiveMQ 5.x you can try using the Qpid JMS v2.1.0 client which does use the Jakarata JMS API but you will need to be somewhat careful as the 5.x broker doesn't support JMS 2.0 so some parts of the API can trigger unexpected behaviors. The AMQP support in the 5.x broker is not as fully integrated and JMS 2.0 aware as that of the Artemis broker so you can encounter issues you wouldn't see if you moved on to the Artemis broker.

Edit: Didn't work so the only way is to upgrade to artemis. That way the codebase is also nearly unchanged.

Upvotes: 4

Related Questions