|
|
|
@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.jms.JmsTemplateAutoConfiguration.JmsTemplateProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
@ -37,13 +38,9 @@ import org.springframework.jms.core.JmsTemplate;
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnClass({ JmsTemplate.class, ConnectionFactory.class })
|
|
|
|
|
@EnableConfigurationProperties(JmsTemplateProperties.class)
|
|
|
|
|
public class JmsTemplateAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnMissingBean(JmsTemplate.class)
|
|
|
|
|
@EnableConfigurationProperties(JmsTemplateProperties.class)
|
|
|
|
|
protected static class JmsTemplateCreator {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JmsTemplateProperties config;
|
|
|
|
|
|
|
|
|
@ -51,21 +48,20 @@ public class JmsTemplateAutoConfiguration {
|
|
|
|
|
private ConnectionFactory connectionFactory;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnMissingBean(JmsTemplate.class)
|
|
|
|
|
public JmsTemplate jmsTemplate() {
|
|
|
|
|
JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory);
|
|
|
|
|
jmsTemplate.setPubSubDomain(this.config.isPubSubDomain());
|
|
|
|
|
return jmsTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ConfigurationProperties(name = "spring.jms")
|
|
|
|
|
public static class JmsTemplateProperties {
|
|
|
|
|
|
|
|
|
|
private boolean pubSubDomain = true;
|
|
|
|
|
|
|
|
|
|
public boolean isPubSubDomain() {
|
|
|
|
|
return pubSubDomain;
|
|
|
|
|
return this.pubSubDomain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPubSubDomain(boolean pubSubDomain) {
|
|
|
|
@ -84,12 +80,14 @@ public class JmsTemplateAutoConfiguration {
|
|
|
|
|
private ActiveMQConnectionFactoryProperties config;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
ConnectionFactory connectionFactory() {
|
|
|
|
|
ConnectionFactory jmsConnectionFactory() {
|
|
|
|
|
if (this.config.isPooled()) {
|
|
|
|
|
PooledConnectionFactory pool = new PooledConnectionFactory();
|
|
|
|
|
pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config.getBrokerURL()));
|
|
|
|
|
pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config
|
|
|
|
|
.getBrokerURL()));
|
|
|
|
|
return pool;
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return new ActiveMQConnectionFactory(this.config.getBrokerURL());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -109,7 +107,8 @@ public class JmsTemplateAutoConfiguration {
|
|
|
|
|
public String getBrokerURL() {
|
|
|
|
|
if (this.inMemory) {
|
|
|
|
|
return "vm://localhost";
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return this.brokerURL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -119,7 +118,7 @@ public class JmsTemplateAutoConfiguration {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isInMemory() {
|
|
|
|
|
return inMemory;
|
|
|
|
|
return this.inMemory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setInMemory(boolean inMemory) {
|
|
|
|
@ -127,7 +126,7 @@ public class JmsTemplateAutoConfiguration {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isPooled() {
|
|
|
|
|
return pooled;
|
|
|
|
|
return this.pooled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPooled(boolean pooled) {
|
|
|
|
|