From 94e542ca3e673b9a402744d18f1136f1547eb4a5 Mon Sep 17 00:00:00 2001 From: Matt Pavlovich Date: Tue, 19 Mar 2024 14:17:11 -0500 Subject: [PATCH] WIP: Reinstate support for auto-configuring an embedded ActiveMQ broker --- .../build.gradle | 1 + .../spring-boot-autoconfigure/build.gradle | 1 + .../jms/activemq/ActiveMQProperties.java | 23 +++++++++++++++++-- .../spring-boot-starter-activemq/build.gradle | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index f52902b08759..d59e784db5ed 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -78,6 +78,7 @@ dependencies { optional("jakarta.servlet:jakarta.servlet-api") optional("javax.cache:cache-api") optional("org.apache.activemq:activemq-client") + optional("org.apache.activemq:activemq-broker") optional("org.apache.commons:commons-dbcp2") { exclude group: "commons-logging", module: "commons-logging" } diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index 13ad7ba4cbd9..a47e76c341ef 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -77,6 +77,7 @@ dependencies { optional("javax.cache:cache-api") optional("javax.money:money-api") optional("org.apache.activemq:activemq-client") + optional("org.apache.activemq:activemq-broker") optional("org.apache.activemq:artemis-jakarta-client") { exclude group: "commons-logging", module: "commons-logging" } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java index 2877479a08e6..84b59691c37e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java @@ -37,6 +37,8 @@ @ConfigurationProperties(prefix = "spring.activemq") public class ActiveMQProperties { + private static final String DEFAULT_EMBEDDED_BROKER_URL = "vm://localhost?broker.persistent=false"; + private static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616"; /** @@ -44,6 +46,12 @@ public class ActiveMQProperties { */ private String brokerUrl; + /** + * Whether the default broker URL should be in memory. Ignored if an explicit broker + * has been specified. + */ + private boolean inMemory = true; + /** * Login user of the broker. */ @@ -83,6 +91,14 @@ public void setBrokerUrl(String brokerUrl) { this.brokerUrl = brokerUrl; } + public boolean isInMemory() { + return this.inMemory; + } + + public void setInMemory(boolean inMemory) { + this.inMemory = inMemory; + } + public String getUser() { return this.user; } @@ -132,8 +148,11 @@ public Packages getPackages() { } String determineBrokerUrl() { - if (this.brokerUrl != null) { - return this.brokerUrl; + if (this.getBrokerUrl() != null) { + return this.getBrokerUrl(); + } + if (this.isInMemory()) { + return DEFAULT_EMBEDDED_BROKER_URL; } return DEFAULT_NETWORK_BROKER_URL; } diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle b/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle index 72f13cd35dfe..945d4872f552 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle @@ -8,4 +8,5 @@ dependencies { api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter")) api("org.springframework:spring-jms") api("org.apache.activemq:activemq-client") + api("org.apache.activemq:activemq-broker") }