Skip to content

Commit

Permalink
Reinstate support for auto-configuring an embedded ActiveMQ broker
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrpav committed Mar 19, 2024
1 parent a4c1b40 commit 31eb469
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
optional("jakarta.servlet:jakarta.servlet-api")
optional("javax.cache:cache-api")
optional("org.apache.activemq:activemq-client-jakarta")
optional("org.apache.activemq:activemq-broker")
optional("org.apache.commons:commons-dbcp2") {
exclude group: "commons-logging", module: "commons-logging"
}
Expand Down
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
optional("javax.cache:cache-api")
optional("javax.money:money-api")
optional("org.apache.activemq:activemq-client-jakarta")
optional("org.apache.activemq:activemq-broker")
optional("org.apache.activemq:artemis-jakarta-client") {
exclude group: "commons-logging", module: "commons-logging"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@
@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";

/**
* URL of the ActiveMQ broker. Auto-generated by default.
*/
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.
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Spring Boot also auto-configures the necessary infrastructure to send and receiv


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

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.

ActiveMQ "Classic" configuration is controlled by external configuration properties in `+spring.activemq.*+`.
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:
ActiveMQ Classic configuration is controlled by external configuration properties in `+spring.activemq.*+`.
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:

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

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



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-jakarta")
api("org.apache.activemq:activemq-broker")
}

0 comments on commit 31eb469

Please sign in to comment.