Skip to content

Commit 31eb469

Browse files
committed
Reinstate support for auto-configuring an embedded ActiveMQ broker
1 parent a4c1b40 commit 31eb469

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ dependencies {
8080
optional("jakarta.servlet:jakarta.servlet-api")
8181
optional("javax.cache:cache-api")
8282
optional("org.apache.activemq:activemq-client-jakarta")
83+
optional("org.apache.activemq:activemq-broker")
8384
optional("org.apache.commons:commons-dbcp2") {
8485
exclude group: "commons-logging", module: "commons-logging"
8586
}

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dependencies {
5050
optional("javax.cache:cache-api")
5151
optional("javax.money:money-api")
5252
optional("org.apache.activemq:activemq-client-jakarta")
53+
optional("org.apache.activemq:activemq-broker")
5354
optional("org.apache.activemq:artemis-jakarta-client") {
5455
exclude group: "commons-logging", module: "commons-logging"
5556
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@
3737
@ConfigurationProperties(prefix = "spring.activemq")
3838
public class ActiveMQProperties {
3939

40+
private static final String DEFAULT_EMBEDDED_BROKER_URL = "vm://localhost?broker.persistent=false";
41+
4042
private static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616";
4143

4244
/**
4345
* URL of the ActiveMQ broker. Auto-generated by default.
4446
*/
4547
private String brokerUrl;
4648

49+
/**
50+
* Whether the default broker URL should be in memory. Ignored if an explicit broker
51+
* has been specified.
52+
*/
53+
private boolean inMemory = true;
54+
4755
/**
4856
* Login user of the broker.
4957
*/
@@ -83,6 +91,14 @@ public void setBrokerUrl(String brokerUrl) {
8391
this.brokerUrl = brokerUrl;
8492
}
8593

94+
public boolean isInMemory() {
95+
return this.inMemory;
96+
}
97+
98+
public void setInMemory(boolean inMemory) {
99+
this.inMemory = inMemory;
100+
}
101+
86102
public String getUser() {
87103
return this.user;
88104
}
@@ -132,8 +148,11 @@ public Packages getPackages() {
132148
}
133149

134150
String determineBrokerUrl() {
135-
if (this.brokerUrl != null) {
136-
return this.brokerUrl;
151+
if (this.getBrokerUrl() != null) {
152+
return this.getBrokerUrl();
153+
}
154+
if (this.isInMemory()) {
155+
return DEFAULT_EMBEDDED_BROKER_URL;
137156
}
138157
return DEFAULT_NETWORK_BROKER_URL;
139158
}

spring-boot-project/spring-boot-docs/src/docs/asciidoc/messaging/jms.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Spring Boot also auto-configures the necessary infrastructure to send and receiv
88

99

1010
[[messaging.jms.activemq]]
11-
=== ActiveMQ "Classic" Support
12-
When https://activemq.apache.org/components/classic[ActiveMQ "Classic"] is available on the classpath, Spring Boot can configure a `ConnectionFactory`.
11+
=== ActiveMQ Classic Support
12+
When https://activemq.apache.org/components/classic[ActiveMQ Classic] is available on the classpath, Spring Boot can configure a `ConnectionFactory`.
1313

1414
NOTE: If you use `spring-boot-starter-activemq`, the necessary dependencies to connect to an ActiveMQ "Classic" instance are provided, as is the Spring infrastructure to integrate with JMS.
1515

16-
ActiveMQ "Classic" configuration is controlled by external configuration properties in `+spring.activemq.*+`.
17-
By default, ActiveMQ "Classic" is auto-configured to use the https://activemq.apache.org/tcp-transport-reference[TCP transport], connecting by default to `tcp://localhost:61616`. The following example shows how to change the default broker URL:
16+
ActiveMQ Classic configuration is controlled by external configuration properties in `+spring.activemq.*+`.
17+
By default, ActiveMQ Classic is auto-configured to use the https://activemq.apache.org/tcp-transport-reference[TCP transport], connecting by default to `tcp://localhost:61616`. The following example shows how to change the default broker URL:
1818

1919
[source,yaml,indent=0,configprops,configblocks]
2020
----
@@ -49,7 +49,7 @@ If you'd rather use native pooling, you can do so by adding a dependency to `org
4949
TIP: See {spring-boot-autoconfigure-module-code}/jms/activemq/ActiveMQProperties.java[`ActiveMQProperties`] for more of the supported options.
5050
You can also register an arbitrary number of beans that implement `ActiveMQConnectionFactoryCustomizer` for more advanced customizations.
5151

52-
By default, ActiveMQ "Classic" creates a destination if it does not yet exist so that destinations are resolved against their provided names.
52+
By default, ActiveMQ Classic creates a destination if it does not yet exist so that destinations are resolved against their provided names.
5353

5454

5555

spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dependencies {
88
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
99
api("org.springframework:spring-jms")
1010
api("org.apache.activemq:activemq-client-jakarta")
11+
api("org.apache.activemq:activemq-broker")
1112
}

0 commit comments

Comments
 (0)