From 894f83fb1381f80f8be9cbc2b01d9bd675343c6e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 7 Jan 2022 14:03:21 +0000 Subject: [PATCH] Upgrade to Artemis 2.20.0 and switch to Jakarta EE 9 JMS API Closes gh-29203 --- .../build.gradle | 9 +-- .../spring-boot-autoconfigure/build.gradle | 9 +-- .../jms/artemis/ArtemisAutoConfiguration.java | 4 +- ...ArtemisConnectionFactoryConfiguration.java | 22 +------ .../jms/artemis/ArtemisProperties.java | 11 +--- ...temisXAConnectionFactoryConfiguration.java | 6 +- .../ArtemisAutoConfigurationTests.java | 61 ++----------------- .../spring-boot-cli/samples/jms.groovy | 2 +- .../spring-boot-cli/test-samples/jms.groovy | 2 +- .../spring-boot-dependencies/build.gradle | 23 ++----- .../src/docs/asciidoc/messaging/jms.adoc | 13 ---- .../spring-boot-starter-artemis/build.gradle | 2 +- 12 files changed, 25 insertions(+), 139 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index f33932cf4f..5612036227 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -145,16 +145,11 @@ dependencies { exclude group: "org.jboss.spec.javax.annotation", module: "jboss-annotations-api_1.3_spec" } testImplementation("jakarta.xml.bind:jakarta.xml.bind-api") - testImplementation("org.apache.activemq:artemis-jms-client") { + testImplementation("org.apache.activemq:artemis-jakarta-client") { exclude group: "commons-logging", module: "commons-logging" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_2.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" } - testImplementation("org.apache.activemq:artemis-jms-server") { + testImplementation("org.apache.activemq:artemis-jakarta-server") { exclude group: "commons-logging", module: "commons-logging" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_2.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jta_1.1_spec" } testImplementation("org.apache.logging.log4j:log4j-to-slf4j") testImplementation("org.aspectj:aspectjrt") diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index babaea75ba..5aaa8fe1d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -48,16 +48,11 @@ dependencies { optional("jakarta.ws.rs:jakarta.ws.rs-api") optional("javax.cache:cache-api") optional("javax.money:money-api") - optional("org.apache.activemq:artemis-jms-client") { + optional("org.apache.activemq:artemis-jakarta-client") { exclude group: "commons-logging", module: "commons-logging" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_2.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" } - optional("org.apache.activemq:artemis-jms-server") { + optional("org.apache.activemq:artemis-jakarta-server") { exclude group: "commons-logging", module: "commons-logging" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_2.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - exclude group: "org.apache.geronimo.specs", module: "geronimo-jta_1.1_spec" } optional("org.apache.commons:commons-dbcp2") { exclude group: "commons-logging", module: "commons-logging" diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfiguration.java index 712a310df0..1ccc712c3c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.jms.artemis; -import javax.jms.ConnectionFactory; +import jakarta.jms.ConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java index 33ca773b33..af2b9dcfd6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,14 @@ package org.springframework.boot.autoconfigure.jms.artemis; -import javax.jms.ConnectionFactory; +import jakarta.jms.ConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.commons.pool2.PooledObject; -import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryFactory; import org.springframework.boot.autoconfigure.jms.JmsProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -83,19 +80,4 @@ class ArtemisConnectionFactoryConfiguration { } - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass({ JmsPoolConnectionFactory.class, PooledObject.class }) - @ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "true") - static class PooledConnectionFactoryConfiguration { - - @Bean(destroyMethod = "stop") - JmsPoolConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) { - ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties) - .createConnectionFactory(ActiveMQConnectionFactory.class); - return new JmsPoolConnectionFactoryFactory(properties.getPool()) - .createPooledConnectionFactory(connectionFactory); - } - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java index 2ec3381564..224f57a2ed 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants; -import org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; -import org.springframework.boot.context.properties.NestedConfigurationProperty; /** * Configuration properties for Artemis. @@ -71,9 +69,6 @@ public class ArtemisProperties { private final Embedded embedded = new Embedded(); - @NestedConfigurationProperty - private final JmsPoolConnectionFactoryProperties pool = new JmsPoolConnectionFactoryProperties(); - public ArtemisMode getMode() { return this.mode; } @@ -142,10 +137,6 @@ public class ArtemisProperties { return this.embedded; } - public JmsPoolConnectionFactoryProperties getPool() { - return this.pool; - } - /** * Configuration for an embedded Artemis server. */ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisXAConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisXAConnectionFactoryConfiguration.java index 77bff3666a..466d173c3e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisXAConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisXAConnectionFactoryConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.jms.artemis; -import javax.jms.ConnectionFactory; -import javax.transaction.TransactionManager; +import jakarta.jms.ConnectionFactory; +import jakarta.transaction.TransactionManager; import org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java index 515a4306bf..b662898bdd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.UUID; -import javax.jms.ConnectionFactory; -import javax.jms.Message; -import javax.jms.TextMessage; +import jakarta.jms.ConnectionFactory; +import jakarta.jms.Message; +import jakarta.jms.TextMessage; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; @@ -43,7 +43,6 @@ import org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationI import org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; @@ -321,58 +320,6 @@ class ArtemisAutoConfigurationTests { }); } - @Test - void defaultPoolConnectionFactoryIsApplied() { - this.contextRunner.withPropertyValues("spring.artemis.pool.enabled=true").run((context) -> { - assertThat(context.getBeansOfType(JmsPoolConnectionFactory.class)).hasSize(1); - JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class); - JmsPoolConnectionFactory defaultFactory = new JmsPoolConnectionFactory(); - assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) - .isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull()); - assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) - .isEqualTo(defaultFactory.getBlockIfSessionPoolIsFullTimeout()); - assertThat(connectionFactory.getConnectionIdleTimeout()) - .isEqualTo(defaultFactory.getConnectionIdleTimeout()); - assertThat(connectionFactory.getMaxConnections()).isEqualTo(defaultFactory.getMaxConnections()); - assertThat(connectionFactory.getMaxSessionsPerConnection()) - .isEqualTo(defaultFactory.getMaxSessionsPerConnection()); - assertThat(connectionFactory.getConnectionCheckInterval()) - .isEqualTo(defaultFactory.getConnectionCheckInterval()); - assertThat(connectionFactory.isUseAnonymousProducers()).isEqualTo(defaultFactory.isUseAnonymousProducers()); - }); - } - - @Test - void customPoolConnectionFactoryIsApplied() { - this.contextRunner - .withPropertyValues("spring.artemis.pool.enabled=true", "spring.artemis.pool.blockIfFull=false", - "spring.artemis.pool.blockIfFullTimeout=64", "spring.artemis.pool.idleTimeout=512", - "spring.artemis.pool.maxConnections=256", "spring.artemis.pool.maxSessionsPerConnection=1024", - "spring.artemis.pool.timeBetweenExpirationCheck=2048", - "spring.artemis.pool.useAnonymousProducers=false") - .run((context) -> { - assertThat(context.getBeansOfType(JmsPoolConnectionFactory.class)).hasSize(1); - JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class); - assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse(); - assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64); - assertThat(connectionFactory.getConnectionIdleTimeout()).isEqualTo(512); - assertThat(connectionFactory.getMaxConnections()).isEqualTo(256); - assertThat(connectionFactory.getMaxSessionsPerConnection()).isEqualTo(1024); - assertThat(connectionFactory.getConnectionCheckInterval()).isEqualTo(2048); - assertThat(connectionFactory.isUseAnonymousProducers()).isFalse(); - }); - } - - @Test - void poolConnectionFactoryConfiguration() { - this.contextRunner.withPropertyValues("spring.artemis.pool.enabled:true").run((context) -> { - ConnectionFactory factory = getConnectionFactory(context); - assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class); - context.getSourceApplicationContext().close(); - assertThat(factory.createConnection()).isNull(); - }); - } - private ConnectionFactory getConnectionFactory(AssertableApplicationContext context) { assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory"); ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); diff --git a/spring-boot-project/spring-boot-cli/samples/jms.groovy b/spring-boot-project/spring-boot-cli/samples/jms.groovy index bbce82f371..42ab364a65 100644 --- a/spring-boot-project/spring-boot-cli/samples/jms.groovy +++ b/spring-boot-project/spring-boot-cli/samples/jms.groovy @@ -1,7 +1,7 @@ package org.test @Grab("spring-boot-starter-artemis") -@Grab("artemis-jms-server") +@Grab("artemis-jakarta-server") import java.util.concurrent.CountDownLatch @Log diff --git a/spring-boot-project/spring-boot-cli/test-samples/jms.groovy b/spring-boot-project/spring-boot-cli/test-samples/jms.groovy index ad5604cb23..7b3fae617b 100644 --- a/spring-boot-project/spring-boot-cli/test-samples/jms.groovy +++ b/spring-boot-project/spring-boot-cli/test-samples/jms.groovy @@ -1,5 +1,5 @@ @Grab("spring-boot-starter-artemis") -@Grab("artemis-jms-server") +@Grab("artemis-jakarta-server") import java.util.concurrent.CountDownLatch @Log diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 3b26e86395..5630fbffe1 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -31,28 +31,17 @@ bom { ] } } - library("Artemis", "2.19.0") { + library("Artemis", "2.20.0") { group("org.apache.activemq") { modules = [ "artemis-amqp-protocol", - "artemis-commons" { - exclude group: "commons-logging", module: "commons-logging" - }, - "artemis-core-client" { - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - }, - "artemis-jms-client" { - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - }, - "artemis-jms-server" { - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - }, + "artemis-commons", + "artemis-core-client", + "artemis-jakarta-client", + "artemis-jakarta-server", "artemis-journal", "artemis-selector", - "artemis-server" { - exclude group: "commons-logging", module: "commons-logging" - exclude group: "org.apache.geronimo.specs", module: "geronimo-json_1.0_spec" - }, + "artemis-server", "artemis-service-extensions" ] } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/messaging/jms.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/messaging/jms.adoc index ac97ad28f0..c78aed7ebd 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/messaging/jms.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/messaging/jms.adoc @@ -43,19 +43,6 @@ By default, a `CachingConnectionFactory` wraps the native `ConnectionFactory` wi 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: - -[source,yaml,indent=0,subs="verbatim",configprops,configblocks] ----- - spring: - artemis: - pool: - enabled: true - max-connections: 50 ----- - -See {spring-boot-autoconfigure-module-code}/jms/artemis/ArtemisProperties.java[`ArtemisProperties`] for more supported options. - No JNDI lookup is involved, and destinations are resolved against their names, using either the `name` attribute in the Artemis configuration or the names provided through configuration. diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/build.gradle index ae02168509..c38a13d499 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/build.gradle @@ -7,7 +7,7 @@ description = "Starter for JMS messaging using Apache Artemis" dependencies { api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) api("org.springframework:spring-jms") - api("org.apache.activemq:artemis-jms-client") { + api("org.apache.activemq:artemis-jakarta-client") { exclude group: "commons-logging", module: "commons-logging" } }