Merge pull request #1638 from hekonsek/spring-boot-amq-mqtt

* spring-boot-amq-mqtt:
  Add ActiveMQ MQTT connection URL auto-detection
pull/1547/merge
Phillip Webb 10 years ago
commit a401454a2a

@ -16,8 +16,13 @@
package org.springframework.boot.autoconfigure.jms.activemq;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
@ -33,6 +38,14 @@ class ActiveMQConnectionFactoryFactory {
private static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616";
private static final Map<String, String> CLASS_BASED_BROKER_URLS;
static {
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("org.apache.activemq.transport.mqtt.MQTTTransport",
"mqtt://localhost:1883");
CLASS_BASED_BROKER_URLS = Collections.unmodifiableMap(map);
}
private final ActiveMQProperties properties;
public ActiveMQConnectionFactoryFactory(ActiveMQProperties properties) {
@ -67,6 +80,13 @@ class ActiveMQConnectionFactoryFactory {
if (this.properties.getBrokerUrl() != null) {
return this.properties.getBrokerUrl();
}
if (this.properties.isAutodetectConnectionUrl()) {
for (Map.Entry<String, String> entry : CLASS_BASED_BROKER_URLS.entrySet()) {
if (ClassUtils.isPresent(entry.getKey(), null)) {
return entry.getValue();
}
}
}
if (this.properties.isInMemory()) {
return DEFAULT_EMBEDDED_BROKER_URL;
}

@ -29,6 +29,8 @@ public class ActiveMQProperties {
private String brokerUrl;
private boolean autodetectConnectionUrl = true;
private boolean inMemory = true;
private boolean pooled;
@ -45,6 +47,14 @@ public class ActiveMQProperties {
this.brokerUrl = brokerUrl;
}
public boolean isAutodetectConnectionUrl() {
return this.autodetectConnectionUrl;
}
public void setAutodetectConnectionUrl(boolean autodetectConnectionUrl) {
this.autodetectConnectionUrl = autodetectConnectionUrl;
}
/**
* Specify if the default broker url should be in memory. Ignored if an explicit
* broker has been specified.

@ -284,6 +284,7 @@ content into your application; rather pick only the properties that you need.
spring.activemq.broker-url=tcp://localhost:61616 # connection URL
spring.activemq.user=
spring.activemq.password=
spring.activemq.autodetect-connection-url=true # attempt to guess URL based on classpath
spring.activemq.in-memory=true # broker kind to create if no broker-url is specified
spring.activemq.pooled=false

Loading…
Cancel
Save