Polish contribution
The properties exposed by the ActiveMQ pooled connection factory are quite specific and I felt it was arbitrary to expose some and not others. However, the number of connections and the timeouts seem the most useful so they have been kept and a `configuration` nested namespace can be used to configure any additional settings. The core properties have been renamed to be less "raw" and more compliant with the structure of other properties. The documentation on fields has also been aligned. Closes gh-5372
This commit is contained in:
parent
e41d42171b
commit
3d4a9d9c84
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2016 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.
|
||||
|
@ -24,6 +24,7 @@ import org.apache.activemq.pool.PooledConnectionFactory;
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -53,6 +54,7 @@ class ActiveMQConnectionFactoryConfiguration {
|
|||
|
||||
@Bean(destroyMethod = "stop")
|
||||
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true", matchIfMissing = false)
|
||||
@ConfigurationProperties("spring.activemq.pool.configuration")
|
||||
public PooledConnectionFactory pooledJmsConnectionFactory(ActiveMQProperties properties) {
|
||||
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(
|
||||
new ActiveMQConnectionFactoryFactory(properties)
|
||||
|
@ -60,20 +62,11 @@ class ActiveMQConnectionFactoryConfiguration {
|
|||
|
||||
ActiveMQProperties.Pool pool = properties.getPool();
|
||||
pooledConnectionFactory.setMaxConnections(pool.getMaxConnections());
|
||||
pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeMillis());
|
||||
pooledConnectionFactory.setMaximumActiveSessionPerConnection(pool.getMaxSessionsPerConnection());
|
||||
pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeMillis());
|
||||
pooledConnectionFactory.setTimeBetweenExpirationCheckMillis(pool.getTimeBetweenEvictionRunsMillis());
|
||||
|
||||
pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeout());
|
||||
pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeout());
|
||||
return pooledConnectionFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "false", matchIfMissing = true)
|
||||
|
||||
public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) {
|
||||
return new ActiveMQConnectionFactoryFactory(properties).createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2016 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.
|
||||
|
@ -94,35 +94,25 @@ public class ActiveMQProperties {
|
|||
protected static class Pool {
|
||||
|
||||
/**
|
||||
* Specify if a PooledConnectionFactory should be created instead of a regular
|
||||
* Whether a PooledConnectionFactory should be created instead of a regular
|
||||
* ConnectionFactory.
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* Sets the maximum number of pooled Connections.
|
||||
* Maximum number of pooled connections.
|
||||
*/
|
||||
private int maxConnections = 1;
|
||||
|
||||
/**
|
||||
* Sets the idle timeout value for Connection's that are created by this pool in Milliseconds.
|
||||
* Connection idle timeout in milliseconds.
|
||||
*/
|
||||
private int idleTimeMillis = 30 * 1000;
|
||||
private int idleTimeout = 30000;
|
||||
|
||||
/**
|
||||
* Allow connections to expire, irrespective of load or idle time.
|
||||
* Connection expiration timeout in milliseconds.
|
||||
*/
|
||||
private long expiryTimeMillis = 0L;
|
||||
|
||||
/**
|
||||
* Sets the maximum number of active sessions per connection.
|
||||
*/
|
||||
private int maxSessionsPerConnection = 500;
|
||||
|
||||
/**
|
||||
* Sets the number of milliseconds to sleep between runs of the idle Connection eviction thread.
|
||||
*/
|
||||
private long timeBetweenEvictionRunsMillis = -1L;
|
||||
private long expiryTimeout = 0;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
|
@ -140,36 +130,21 @@ public class ActiveMQProperties {
|
|||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
public int getIdleTimeMillis() {
|
||||
return this.idleTimeMillis;
|
||||
public int getIdleTimeout() {
|
||||
return this.idleTimeout;
|
||||
}
|
||||
|
||||
public void setIdleTimeMillis(int idleTimeMillis) {
|
||||
this.idleTimeMillis = idleTimeMillis;
|
||||
public void setIdleTimeout(int idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
|
||||
public long getExpiryTimeMillis() {
|
||||
return this.expiryTimeMillis;
|
||||
public long getExpiryTimeout() {
|
||||
return this.expiryTimeout;
|
||||
}
|
||||
|
||||
public void setExpiryTimeMillis(long expiryTimeMillis) {
|
||||
this.expiryTimeMillis = expiryTimeMillis;
|
||||
public void setExpiryTimeout(long expiryTimeout) {
|
||||
this.expiryTimeout = expiryTimeout;
|
||||
}
|
||||
|
||||
public int getMaxSessionsPerConnection() {
|
||||
return this.maxSessionsPerConnection;
|
||||
}
|
||||
|
||||
public void setMaxSessionsPerConnection(int maxSessionsPerConnection) {
|
||||
this.maxSessionsPerConnection = maxSessionsPerConnection;
|
||||
}
|
||||
|
||||
public long getTimeBetweenEvictionRunsMillis() {
|
||||
return this.timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
|
||||
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
|
||||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2016 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.
|
||||
|
@ -21,7 +21,6 @@ import javax.transaction.TransactionManager;
|
|||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.ActiveMQXAConnectionFactory;
|
||||
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
|
@ -46,7 +45,7 @@ import org.springframework.context.annotation.Primary;
|
|||
class ActiveMQXAConnectionFactoryConfiguration {
|
||||
|
||||
@Primary
|
||||
@Bean(name = { "jmsConnectionFactory", "xaJmsConnectionFactory" })
|
||||
@Bean(name = {"jmsConnectionFactory", "xaJmsConnectionFactory"})
|
||||
public ConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
|
||||
XAConnectionFactoryWrapper wrapper) throws Exception {
|
||||
ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(
|
||||
|
@ -62,26 +61,4 @@ class ActiveMQXAConnectionFactoryConfiguration {
|
|||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
}
|
||||
|
||||
@ConditionalOnClass(PooledConnectionFactory.class)
|
||||
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true", matchIfMissing = false)
|
||||
static class PooledConnectionFactoryConfiguration {
|
||||
|
||||
@Bean(destroyMethod = "stop")
|
||||
public PooledConnectionFactory pooledNonXaJmsConnectionFactory(
|
||||
ActiveMQProperties properties) {
|
||||
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(
|
||||
new ActiveMQConnectionFactoryFactory(properties)
|
||||
.createConnectionFactory(ActiveMQConnectionFactory.class));
|
||||
|
||||
ActiveMQProperties.Pool pool = properties.getPool();
|
||||
pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeMillis());
|
||||
pooledConnectionFactory.setMaxConnections(pool.getMaxConnections());
|
||||
pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeMillis());
|
||||
pooledConnectionFactory.setMaximumActiveSessionPerConnection(pool.getMaxSessionsPerConnection());
|
||||
pooledConnectionFactory.setTimeBetweenExpirationCheckMillis(pool.getTimeBetweenEvictionRunsMillis());
|
||||
|
||||
return pooledConnectionFactory;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import static org.mockito.Mockito.mockingDetails;
|
|||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Aurélien Leboulanger
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ActiveMQAutoConfigurationTests {
|
||||
|
||||
|
@ -62,15 +63,14 @@ public class ActiveMQAutoConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void custompooledConnectionFactoryConfiguration() {
|
||||
public void customPooledConnectionFactoryConfiguration() {
|
||||
load(EmptyConfiguration.class,
|
||||
"spring.activemq.pool.enabled:true",
|
||||
"spring.activemq.pool.max-connections:256",
|
||||
"spring.activemq.pool.idle-time-millis:512",
|
||||
"spring.activemq.pool.max-sessions-per-connection:1024",
|
||||
"spring.activemq.pool.time-between-eviction-runs-millis:2048",
|
||||
"spring.activemq.pool.expiry-time-millis:4096"
|
||||
);
|
||||
"spring.activemq.pool.maxConnections:256",
|
||||
"spring.activemq.pool.idleTimeout:512",
|
||||
"spring.activemq.pool.expiryTimeout:4096",
|
||||
"spring.activemq.pool.configuration.maximumActiveSessionPerConnection:1024",
|
||||
"spring.activemq.pool.configuration.timeBetweenExpirationCheckMillis:2048");
|
||||
ConnectionFactory connectionFactory = this.context.getBean(ConnectionFactory.class);
|
||||
assertThat(connectionFactory).isInstanceOf(PooledConnectionFactory.class);
|
||||
|
||||
|
@ -89,8 +89,7 @@ public class ActiveMQAutoConfigurationTests {
|
|||
.getBean(ConnectionFactory.class);
|
||||
assertThat(connectionFactory).isInstanceOf(PooledConnectionFactory.class);
|
||||
this.context.close();
|
||||
assertThat(((PooledConnectionFactory) connectionFactory).createConnection())
|
||||
.isNull();
|
||||
assertThat(connectionFactory.createConnection()).isNull();
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
|
|
|
@ -727,12 +727,11 @@ content into your application; rather pick only the properties that you need.
|
|||
spring.activemq.in-memory=true # Specify if the default broker URL should be in memory. Ignored if an explicit broker has been specified.
|
||||
spring.activemq.password= # Login password of the broker.
|
||||
spring.activemq.user= # Login user of the broker.
|
||||
spring.activemq.pool.enabled=false # Specify if a PooledConnectionFactory should be created instead of a regular ConnectionFactory.
|
||||
spring.activemq.pool.max-connections=1 # The maximum number of pooled Connections
|
||||
spring.activemq.pool.max-sessions-per-connection=500 # The maximum number of active sessions per connection
|
||||
spring.activemq.pool.time-between-eviction-runs-millis=-1 # The number of milliseconds to sleep between runs of the idle Connection eviction thread.
|
||||
spring.activemq.pool.idle-time-millis=30000 # The idle timeout value for Connection's that are created by this pool (in Milliseconds)
|
||||
spring.activemq.pool.expiry-time-millis=0 # Allow connections to expire, irrespective of load or idle time
|
||||
spring.activemq.pool.configuration.*= # See PooledConnectionFactory
|
||||
spring.activemq.pool.enabled=false # Whether a PooledConnectionFactory should be created instead of a regular ConnectionFactory.
|
||||
spring.activemq.pool.expiry-timeout=0 # Connection expiration timeout in milliseconds.
|
||||
spring.activemq.pool.idle-timeout=30000 # Connection idle timeout in milliseconds.
|
||||
spring.activemq.pool.max-connections=1 # Maximum number of pooled connections.
|
||||
|
||||
# ARTEMIS ({sc-spring-boot-autoconfigure}/jms/artemis/ArtemisProperties.{sc-ext}[ArtemisProperties])
|
||||
spring.artemis.embedded.cluster-password= # Cluster password. Randomly generated on startup by default.
|
||||
|
|
Loading…
Reference in New Issue