Migrating to Spring Boot 3 with ActiveMQ Classic
Asked Answered
C

5

16

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

Cornwallis answered 2/12, 2022 at 9:22 Comment(2)
Keep in mind that Spring Boot 3 uses Jakarta EE 9 which, in turn, uses Jakarta Messaging 3.0 which includes all the changes from JMS 2.0 which ActiveMQ "Classic" doesn't support.Farika
As a follow up you can use again the spring boot starter activemq with version 2.7.12 (should be set automatically in Spring Boot 3.1.0 Parent)Cornwallis
N
6

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.

Norbertonorbie answered 18/4, 2023 at 10:20 Comment(7)
You need activemq-client-jakarta 5.18.1 for a minor bug fixNedranedrah
I just add that if you want to use JmsTemplate, don't forget to add also org.springframework:spring-jms dependencyAwestricken
What about using embedded ActiveMQ? After upgrading to Spring boot 3.1.2, it doesn't start. I also tested spring-boot-starter-activemq, result was same.Kakaaba
@Kakaaba Embedded ActiveMQ is not (yet) supported: "Support for an embedded ActiveMQ broker has not be restored as ActiveMQ’s broker does not yet support JMS 3.0." Spring Boot 3.1 - Release notes :(Moralize
UPDATE (2023-12) Spring Boot 3.3 is planning to re-introduce full broker support to the spring-boot-starter-activemq with ActiveMQ v6.0.1. Follow: github.com/spring-projects/spring-boot/issues/38404Nedranedrah
I'm sorry if my question is not in the right place but is this kind of configuration expected to work with broker-url: tcp://localhost:61616 when using Spring Boot 3.2 and ActiveMQ 5.18.3?Flirtatious
As Matt Pavlovich suggested, the answer could now include ActiveMQ version V6.0.1 which is compatible with jdk 17 (jakarta instead of javax)Francium
N
5

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

Nedranedrah answered 9/12, 2022 at 15:27 Comment(4)
Any update when this might be completed?Sharenshargel
A new client has been published. I will check it out next week.Cornwallis
Jakarta JMS compatible version ActiveMQ 5.18.0 released [ANN] Apache ActiveMQ 5.18.0 has been released, but it still lack on support from spring sideNataline
You need 5.18.1 for minor bug fixNedranedrah
K
5

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>
    
Kakaaba answered 10/8, 2023 at 22:46 Comment(4)
You can now do the reverse thing. It is again included in the standard spring-boot-starter-activemq.Cornwallis
I just found this way to migrate to Spring Boot 3.1.2. Do you have a way to have the embedded ActiveMQ and JmsTemplate with spring-boot-starter-activemq?Kakaaba
@Kakaaba Following dependencies works for me: 1. spring-boot-starter-activemq version: 3.2.2 - I am using springboot 3.2.2 2. activemq-broker version: 5.18.3 3. javax.jms-api version:2.0.1Fitzwater
@PavanKumar With these dependencies, does the embedded activeMQ works?Parturition
H
4

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.

Heterotopia answered 2/12, 2022 at 15:27 Comment(3)
Thanks for the detailed explanation. I use ActiveMQ only for sending and receiving simple queue messages. I will try Qpid and update my question if I was succesful in connecting to the ActiveMQ "Classic" server.Cornwallis
Be sure to enable an AMQP transport connector in the ActiveMQ config file and point the client to the correct port (AMQP default port is 5672 for TCP, and 5671 for SSL).Heterotopia
Sorry. Edited the wrong comment. I guess the cleanest solution is to update to spring boot artemis server.Cornwallis
B
1

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

Breakfast answered 19/12, 2022 at 19:28 Comment(6)
Hi, adding a spring 5.3.x dependency to a spring 6.0.x app sounds a bit dangerous.Freddyfredek
Thanks I will try that solution even if it is quite a hack.Cornwallis
@Cornwallis did you get it to work? In out system we are using SpringIntegration and ActiveMQ. Had plans now to update to SpringBoot 3 from 2, but the problem is that the broker is not on our side, so we cannot just switch to Artemis like that...Contemplate
Hi. I was able to add these dependencies without a problem and it didn't crash at start. But I also didn't see a log message with "Successfully connected to queue". I will continue with testing hopefully by the end of the week.Cornwallis
Hi, The provided solution worked for me as well. But I had to add this dependency. <dependency> <groupId>javax.jms</groupId> <artifactId>javax.jms-api</artifactId> <version>2.0.1</version> </dependency>Elude
Use activemq-client-jakarta v5.18.1Nedranedrah

© 2022 - 2024 — McMap. All rights reserved.