Migrating to Spring Boot 3 with ActiveMQ "Classic" - spring-boot

I am trying to migrate to Spring Boot 3 with the new namespace jakarta.xx instead of javax.xx 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 artemis. That way the codebase is also nearly unchanged.

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.

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: A temporary, jakarta-based client suitable for transition activity is available: https://github.com/hyteio/activemq-client-jakarta

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

Related

ActiveMQ Artemis vs ActiveMQ "Classic" connection

Is there any difference between ActiveMQ Artemis connection configuration between aplication.yaml:
spring.artemis.mode=native
spring.artemis.host=192.168.1.210
spring.artemis.port=9876
vs
spring.activemq.broker-url=tcp://192.168.1.210:9876
spring.activemq.user=admin
spring.activemq.password=secret
If you use only this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-artemis</artifactId>
</dependency>
I assume that spring-boot-starter-artemis allows you to connect via JMS, and that is spring.activemq.XXX, and if you want to connect in the Artemis approach then you use spring.artemis.XXX the bean will autocofigure.
But I am not sure
I read the key differences on this page.
Which one is better? For JMS (ActiveMQConnectionFactory) I can use CachingConnectionFactory, is it needed for artemis auto-configuration?
If you're using spring-boot-starter-artemis that indicates you want to connect to an instance of ActiveMQ Artemis which means you'll want to configure spring.artemis.XXX properties. Assuming you're using spring-boot-starter-artemis 2.7.0 (i.e. the latest) you'll want to use spring.activemq.broker-url as referenced in the Spring documentation, e.g.:
spring.artemis.mode=native
spring.artemis.broker-url=tcp://192.168.1.210:9876
spring.artemis.user=admin
spring.artemis.password=secret
The host and port properties you referenced were deprecated in favor of broker-url awhile back.
The documentation continues:
By default, a CachingConnectionFactory wraps the native ConnectionFactory with sensible settings that you can control by external configuration properties in spring.jms.*:
spring.jms.cache.session-cache-size=5
If you’d rather use native pooling, you can do so by adding a dependency to org.messaginghub:pooled-jms and configuring the JmsPoolConnectionFactory accordingly, as shown in the following example:
spring.artemis.pool.enabled=true
spring.artemis.pool.max-connections=50
Whether you use spring-boot-starter-artemis with spring.artemis.XXX properties or spring-boot-starter-activemq with spring.activemq.XXX properties the underlying Spring components will use JMS to connect.

How do I setup RabbitMQ with JMS and AMQP 1.0?

I need to send messages to RabbitMQ through AMQP 1.0 and receive them with #JmsListener in Spring Boot. I've discovered there are two specific plugins for RabbitMQ that add support for AMQP 1.0 and JMS.
The JMS plugin is meant to be used with RabbitMQ's JMS Client library but on the AMQP 1.0 github they say that SwiftMQ Java Client is the one that works properly.
What I don't understand is, what do I need to use to fulfill the above requirements? How do I set it up?
You could just use the Qpid JMS client library. It implements JMS so it will integrate with Spring JMS and it speaks AMQP 1.0 over the wire so it will work with RabbitMQ + AMQP 1.0 plugin.

Not able to configure JMS 2.0, ActiveMQ 5.x, and Karaf

I have been trying to setup pax-jms with ActiveMQ in Apache karaf. Following are the respective versions, that I have installed:
activemq-osgi: 5.15.3
OPS4J Pax JMS * : 1.0.3
Karaf: 4.2.0
JMS API: 2.0.1
These are the features that I had installed:
> feature:repo-add mvn:org.ops4j.pax.jms/pax-jms-features/1.0.3/xml/features
> feature:install pax-jms-activemq pax-jms-config
I can see that my configurations are being picked up properly. Thus, executing the command jms:connectionfactories shows the connection that I had configured.
Note: I followed https://ops4j1.jira.com/wiki/spaces/PAXJMS/pages/331350050/Configuration, believing that the steps would have been similar for ActiveMQ as well.
My configuration looks as follows:
jms.url=tcp://localhost:61616
jms.username=system
jms.password=manager
type=activemq
osgi.jndi.service.name=jms/demo.consumer
For the time being, I just wanted to test whether or not I can query the ActiveMQ broker from Karaf. Thus, I tried jms:info jms/demo.consumer. But, I am consistently getting the following error message:
Error executing command: JMS 2.0 is not supported by ActiveMQ
I have tried changing the versions, tried on fresh karaf instances as well. But, I had no luck so far. Am I missing some fundamental steps here?
The pax-jms-activemq module support ActiveMQ 5.x. The command line tools may not work b/c it calls ConnectionFactory.createContext() instead of .createConnection(). JMS v2.0 has a couple features that ActiveMQ 5.x does not support-- shared durable subscriptions, basically.
As long as the code that gets the ConnectionFactory calls .createConnection() instead of .createContext() it'll work just fine with the JMS API 2.0 jars. Java code, camel-activemq, camel-jms, etc will all work fine.
The error message is accurate. ActiveMQ 5.x doesn't support JMS 2.0. This isn't a configuration issue. It's simply not implemented. If you want JMS 2.0 support from an ActiveMQ broker then you should use ActiveMQ Artemis. For what it's worth, the documentation you referenced is using ActiveMQ Artemis.

JMS 2.0 support in Mule

I was trying out for the possibility to use JMS 2.0 in Mule. In my research I found that ActiveMQ supports JMS 2.0 with the combination of Spring 4.1.0.RELEASE here
Can any one suggest the ways to use JMS 2.0 in Mule ESB using above please.
Thanks .!!
Mule 4 JMS connector is fully complaint with JMS 2.0.
JMS connector is
Fully compliant with JMS 2.0, 1.1, and 1.0.2 specifications.
I'm afraid there is no JMS2.0 support in MuleESB at this very moment, just 1.0.2b and 1.1. It has been on the radar for a while but no plans to support it yet.
Which features of JMS2.0 do you need? If it's competing consumers on topics are supported with activemq and 1.1 with virtual topics, and there is also a more poweful scheduled send than what it is in 2.0.

How to use AMQP instead of JMS with Ehcache?

Ehcache supports OpenMQ and ActiveMQ natively and uses JMS for synchronization.
Is it possible to use RabbitMQ with AMQP instead ?
I am aware of https://github.com/jamescarr/ehcache-amqpreplication/pull/2 project but it seems to be old and not used by larger community.
Is there an alternative? What exactly must be done to use AMQP and RabbitMQ in Ehcache?

Resources