mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Revisit JMS support
Since ActiveMQ 5.8.0, the modules structure has been revisited and activemq-core no longer exists. The activemq-broker is required to create an embedded broker. Since Boot creates such broker by default if ConnectionFactory is present, a condition has been added to do so only when the necessary classes are present in the classpath. The default embedded broker is now configured to disable message persistence altogether as this requires an extra jar since 5.8.0, i.e. activemq-kahadb-store. Split the ActiveMQ auto configuration from the JmsTemplate auto configuration so these are totally independent. ActiveMQAutoConfiguration has been created to detect and configure the ActiveMQ broker if necessary. The brokerUrl parameter was ignored as long as the inMemory parameter was true. The actual brokerUrl to use is now determined by the user defined values of those parameters: if the brokerUrl is set, it is always used. If no brokerUrl is set, the value of inMemory determines if an embedded broker should be used (true) or a tcp connection to an existing local broker (false). JmsTemplateAutoConfiguration now creates a JmsTemplate only if a ConnectionFactory is available. Fixes gh-872, gh-882, gh-883
This commit is contained in:
parent
401e2c8b6f
commit
e695e5d637
@ -48,7 +48,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
<artifactId>activemq-broker</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.transport.vm.VMTransportFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} to integrate with
|
||||
* an ActiveMQ broker.
|
||||
*
|
||||
* <p>Validates that the classpath contain the necessary classes before
|
||||
* starting an embedded broker.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore(JmsTemplateAutoConfiguration.class)
|
||||
@ConditionalOnClass({ConnectionFactory.class, ActiveMQConnectionFactory.class})
|
||||
@ConditionalOnMissingBean(ConnectionFactory.class)
|
||||
public class ActiveMQAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(VMTransportFactory.class)
|
||||
@Conditional(EmbeddedBrokerCondition.class)
|
||||
@Import(ActiveMQConnectionFactoryConfiguration.class)
|
||||
protected static class EmbeddedBroker {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Conditional(NonEmbeddedBrokerCondition.class)
|
||||
@Import(ActiveMQConnectionFactoryConfiguration.class)
|
||||
protected static class NetworkBroker {
|
||||
}
|
||||
|
||||
static abstract class BrokerTypeCondition extends SpringBootCondition {
|
||||
private final boolean embedded;
|
||||
|
||||
BrokerTypeCondition(boolean embedded) {
|
||||
this.embedded = embedded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
String brokerUrl = ActiveMQProperties.determineBrokerUrl(context.getEnvironment());
|
||||
boolean match = brokerUrl.contains("vm://");
|
||||
boolean outcome = (match == this.embedded);
|
||||
return new ConditionOutcome(outcome, buildMessage(brokerUrl, outcome));
|
||||
}
|
||||
|
||||
protected String buildMessage(String brokerUrl, boolean outcome) {
|
||||
String brokerType = embedded ? "Embedded" : "Network";
|
||||
String detected = outcome ? "detected" : "not detected";
|
||||
return brokerType + " ActiveMQ broker " + detected + " - brokerUrl '" + brokerUrl + "'";
|
||||
}
|
||||
}
|
||||
|
||||
static class EmbeddedBrokerCondition extends BrokerTypeCondition {
|
||||
|
||||
EmbeddedBrokerCondition() {
|
||||
super(true);
|
||||
}
|
||||
}
|
||||
|
||||
static class NonEmbeddedBrokerCondition extends BrokerTypeCondition {
|
||||
|
||||
NonEmbeddedBrokerCondition() {
|
||||
super(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Creates a {@link ConnectionFactory} based on {@link ActiveMQProperties}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ActiveMQProperties.class)
|
||||
class ActiveMQConnectionFactoryConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ActiveMQProperties config;
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory jmsConnectionFactory() {
|
||||
ConnectionFactory connectionFactory = getActiveMQConnectionFactory();
|
||||
if (this.config.isPooled()) {
|
||||
PooledConnectionFactory pool = new PooledConnectionFactory();
|
||||
pool.setConnectionFactory(connectionFactory);
|
||||
return pool;
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
private ConnectionFactory getActiveMQConnectionFactory() {
|
||||
if (StringUtils.hasLength(this.config.getUser())
|
||||
&& StringUtils.hasLength(this.config.getPassword())) {
|
||||
return new ActiveMQConnectionFactory(this.config.getUser(),
|
||||
this.config.getPassword(), this.config.getBrokerUrl());
|
||||
}
|
||||
return new ActiveMQConnectionFactory(this.config.getBrokerUrl());
|
||||
}
|
||||
}
|
@ -16,17 +16,25 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertyResolver;
|
||||
|
||||
/**
|
||||
* Configuration properties for ActiveMQ
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.activemq")
|
||||
public class ActiveMQProperties {
|
||||
|
||||
private String brokerUrl = "tcp://localhost:61616";
|
||||
public static final String DEFAULT_EMBEDDED_BROKER_URL = "vm://localhost?broker.persistent=false";
|
||||
|
||||
public static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616";
|
||||
|
||||
private String brokerUrl = null;
|
||||
|
||||
private boolean inMemory = true;
|
||||
|
||||
@ -36,18 +44,35 @@ public class ActiveMQProperties {
|
||||
|
||||
private String password;
|
||||
|
||||
// Will override brokerURL if inMemory is set to true
|
||||
/**
|
||||
* Determine the broker url to use for the specified {@link Environment}.
|
||||
* <p>If no broker url is specified through configuration, a default
|
||||
* broker is provided, that is {@value #DEFAULT_EMBEDDED_BROKER_URL} if
|
||||
* the {@code inMemory} flag is {@code null} or {@code true},
|
||||
* {@value #DEFAULT_NETWORK_BROKER_URL} otherwise.
|
||||
*
|
||||
* @param environment the environment to extract configuration from
|
||||
* @return the broker url to use
|
||||
*/
|
||||
public static String determineBrokerUrl(Environment environment) {
|
||||
PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.activemq.");
|
||||
String brokerUrl = resolver.getProperty("brokerUrl");
|
||||
Boolean inMemory = resolver.getProperty("inMemory", Boolean.class);
|
||||
return determineBrokerUrl(brokerUrl, inMemory);
|
||||
}
|
||||
|
||||
public String getBrokerUrl() {
|
||||
if (this.inMemory) {
|
||||
return "vm://localhost";
|
||||
}
|
||||
return this.brokerUrl;
|
||||
return determineBrokerUrl(this.brokerUrl, this.inMemory);
|
||||
}
|
||||
|
||||
public void setBrokerUrl(String brokerUrl) {
|
||||
this.brokerUrl = brokerUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the default broker url should be in memory. Ignored
|
||||
* if an explicit broker has been specified.
|
||||
*/
|
||||
public boolean isInMemory() {
|
||||
return this.inMemory;
|
||||
}
|
||||
@ -80,4 +105,22 @@ public class ActiveMQProperties {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see #determineBrokerUrl(Environment)
|
||||
*/
|
||||
private static String determineBrokerUrl(String brokerUrl, Boolean inMemory) {
|
||||
boolean embedded = (inMemory != null) ? inMemory : true;
|
||||
|
||||
if (brokerUrl != null) {
|
||||
return brokerUrl;
|
||||
}
|
||||
else if (embedded) {
|
||||
return DEFAULT_EMBEDDED_BROKER_URL;
|
||||
}
|
||||
else {
|
||||
return DEFAULT_NETWORK_BROKER_URL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,25 +18,24 @@ package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link JmsTemplate}.
|
||||
*
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ JmsTemplate.class, ConnectionFactory.class })
|
||||
@ConditionalOnClass(JmsTemplate.class)
|
||||
@ConditionalOnBean(ConnectionFactory.class)
|
||||
@EnableConfigurationProperties(JmsTemplateProperties.class)
|
||||
public class JmsTemplateAutoConfiguration {
|
||||
|
||||
@ -54,34 +53,4 @@ public class JmsTemplateAutoConfiguration {
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(ActiveMQConnectionFactory.class)
|
||||
@ConditionalOnMissingBean(ConnectionFactory.class)
|
||||
@EnableConfigurationProperties(ActiveMQProperties.class)
|
||||
protected static class ActiveMQConnectionFactoryCreator {
|
||||
|
||||
@Autowired
|
||||
private ActiveMQProperties config;
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory jmsConnectionFactory() {
|
||||
ConnectionFactory connectionFactory = getActiveMQConnectionFactory();
|
||||
if (this.config.isPooled()) {
|
||||
PooledConnectionFactory pool = new PooledConnectionFactory();
|
||||
pool.setConnectionFactory(connectionFactory);
|
||||
return pool;
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
private ConnectionFactory getActiveMQConnectionFactory() {
|
||||
if (StringUtils.hasLength(this.config.getUser())
|
||||
&& StringUtils.hasLength(this.config.getPassword())) {
|
||||
return new ActiveMQConnectionFactory(this.config.getUser(),
|
||||
this.config.getPassword(), this.config.getBrokerUrl());
|
||||
}
|
||||
return new ActiveMQConnectionFactory(this.config.getBrokerUrl());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jms.ActiveMQAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jms.JmsTemplateAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ActiveMQPropertiesTests {
|
||||
|
||||
private final ActiveMQProperties properties = new ActiveMQProperties();
|
||||
private final StandardEnvironment environment = new StandardEnvironment();
|
||||
|
||||
@Test
|
||||
public void determineBrokerUrlDefault() {
|
||||
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
|
||||
ActiveMQProperties.determineBrokerUrl(this.environment));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineBrokerUrlVmBrokerUrl() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"spring.activemq.brokerUrl:vm://localhost?persistent=true");
|
||||
assertEquals("vm://localhost?persistent=true",
|
||||
ActiveMQProperties.determineBrokerUrl(this.environment));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineBrokerUrlInMemoryFlag() {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||
"spring.activemq.inMemory:false");
|
||||
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL,
|
||||
ActiveMQProperties.determineBrokerUrl(this.environment));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlIsInMemoryByDefault() {
|
||||
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL, this.properties.getBrokerUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlUseExplicitBrokerUrl() {
|
||||
this.properties.setBrokerUrl("vm://foo-bar");
|
||||
assertEquals("vm://foo-bar", this.properties.getBrokerUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlWithInMemorySetToFalse() {
|
||||
this.properties.setInMemory(false);
|
||||
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL, this.properties.getBrokerUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExplicitBrokerUrlAlwaysWins() {
|
||||
this.properties.setBrokerUrl("vm://foo-bar");
|
||||
this.properties.setInMemory(false);
|
||||
assertEquals("vm://foo-bar", this.properties.getBrokerUrl());
|
||||
}
|
||||
}
|
@ -45,9 +45,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultJmsTemplate() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
ActiveMQConnectionFactory connectionFactory = this.context
|
||||
@ -55,14 +53,13 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
assertNotNull(jmsTemplate);
|
||||
assertNotNull(connectionFactory);
|
||||
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
|
||||
assertEquals("vm://localhost", ((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
|
||||
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
|
||||
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionFactoryBackoff() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration2.class,
|
||||
JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration2.class);
|
||||
this.context.refresh();
|
||||
assertEquals("foobar", this.context.getBean(ActiveMQConnectionFactory.class)
|
||||
.getBrokerURL());
|
||||
@ -70,9 +67,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testJmsTemplateBackoff() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration3.class,
|
||||
JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration3.class);
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
assertEquals(999, jmsTemplate.getPriority());
|
||||
@ -80,9 +75,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testJmsTemplateBackoffEverything() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration2.class, TestConfiguration3.class,
|
||||
JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration2.class, TestConfiguration3.class);
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
assertEquals(999, jmsTemplate.getPriority());
|
||||
@ -92,9 +85,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testPubSubDisabledByDefault() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
assertFalse(jmsTemplate.isPubSubDomain());
|
||||
@ -102,9 +93,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testJmsTemplatePostProcessedSoThatPubSubIsTrue() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(TestConfiguration4.class,
|
||||
JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration4.class);
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
assertTrue(jmsTemplate.isPubSubDomain());
|
||||
@ -112,9 +101,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testJmsTemplateOverridden() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils
|
||||
.addEnvironment(this.context, "spring.jms.pubSubDomain:false");
|
||||
this.context.refresh();
|
||||
@ -129,9 +116,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testActiveMQOverriddenStandalone() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.activemq.inMemory:false");
|
||||
this.context.refresh();
|
||||
@ -141,17 +126,14 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
assertNotNull(jmsTemplate);
|
||||
assertNotNull(connectionFactory);
|
||||
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
|
||||
assertEquals("tcp://localhost:61616",
|
||||
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL,
|
||||
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveMQOverriddenRemoteHost() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.activemq.inMemory:false",
|
||||
"spring.activemq.brokerUrl:tcp://remote-host:10000");
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
@ -166,9 +148,7 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testActiveMQOverriddenPool() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true");
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
@ -179,14 +159,12 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
assertEquals(jmsTemplate.getConnectionFactory(), pool);
|
||||
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
|
||||
.getConnectionFactory();
|
||||
assertEquals("vm://localhost", factory.getBrokerURL());
|
||||
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL, factory.getBrokerURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveMQOverriddenPoolAndStandalone() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true",
|
||||
"spring.activemq.inMemory:false");
|
||||
this.context.refresh();
|
||||
@ -198,16 +176,13 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
assertEquals(jmsTemplate.getConnectionFactory(), pool);
|
||||
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
|
||||
.getConnectionFactory();
|
||||
assertEquals("tcp://localhost:61616", factory.getBrokerURL());
|
||||
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL, factory.getBrokerURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveMQOverriddenPoolAndRemoteServer() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context
|
||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
this.context = createContext(TestConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true",
|
||||
"spring.activemq.inMemory:false",
|
||||
"spring.activemq.brokerUrl:tcp://remote-host:10000");
|
||||
this.context.refresh();
|
||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||
@ -221,6 +196,13 @@ public class JmsTemplateAutoConfigurationTests {
|
||||
assertEquals("tcp://remote-host:10000", factory.getBrokerURL());
|
||||
}
|
||||
|
||||
private AnnotationConfigApplicationContext createContext(Class<?>... additionalClasses) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(additionalClasses);
|
||||
context.register(ActiveMQAutoConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||
return context;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class TestConfiguration {
|
||||
}
|
||||
|
@ -388,6 +388,11 @@
|
||||
<artifactId>activemq-client</artifactId>
|
||||
<version>${activemq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-broker</artifactId>
|
||||
<version>${activemq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-pool</artifactId>
|
||||
|
@ -200,7 +200,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.in-memory=true
|
||||
spring.activemq.in-memory=true # broker kind to create if no broker-url is specified
|
||||
spring.activemq.pooled=false
|
||||
|
||||
# JMS ({sc-spring-boot-autoconfigure}/jms/JmsTemplateProperties.{sc-ext}[JmsTemplateProperties])
|
||||
|
Loading…
Reference in New Issue
Block a user