Deprecate PooledConnectionFactory properties

This commit deprecated the properties of `PooledConnectionFactory` that
are no longer supported by an alternative that is a JMS 2 compliant.

This commit also adds a note to warn users that this pool implementation
is not JMS 2 compliant.

Closes gh-13956
pull/14003/head
Stephane Nicoll 6 years ago
parent be2c7bf6ea
commit d31f68380a

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/** /**
* Configuration properties for ActiveMQ. * Configuration properties for ActiveMQ.
@ -228,6 +229,7 @@ public class ActiveMQProperties {
this.blockIfFullTimeout = blockIfFullTimeout; this.blockIfFullTimeout = blockIfFullTimeout;
} }
@DeprecatedConfigurationProperty
public boolean isCreateConnectionOnStartup() { public boolean isCreateConnectionOnStartup() {
return this.createConnectionOnStartup; return this.createConnectionOnStartup;
} }
@ -236,6 +238,7 @@ public class ActiveMQProperties {
this.createConnectionOnStartup = createConnectionOnStartup; this.createConnectionOnStartup = createConnectionOnStartup;
} }
@DeprecatedConfigurationProperty(reason = "Use idle-timeout instead")
public Duration getExpiryTimeout() { public Duration getExpiryTimeout() {
return this.expiryTimeout; return this.expiryTimeout;
} }
@ -269,6 +272,7 @@ public class ActiveMQProperties {
this.maximumActiveSessionPerConnection = maximumActiveSessionPerConnection; this.maximumActiveSessionPerConnection = maximumActiveSessionPerConnection;
} }
@DeprecatedConfigurationProperty(reason = "Disabling this option will likely lead to broken connections in the pool.")
public boolean isReconnectOnException() { public boolean isReconnectOnException() {
return this.reconnectOnException; return this.reconnectOnException;
} }

@ -138,10 +138,6 @@ public class ActiveMQAutoConfigurationTests {
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout())
.isEqualTo( .isEqualTo(
defaultFactory.getBlockIfSessionPoolIsFullTimeout()); defaultFactory.getBlockIfSessionPoolIsFullTimeout());
assertThat(connectionFactory.isCreateConnectionOnStartup())
.isEqualTo(defaultFactory.isCreateConnectionOnStartup());
assertThat(connectionFactory.getExpiryTimeout())
.isEqualTo(defaultFactory.getExpiryTimeout());
assertThat(connectionFactory.getIdleTimeout()) assertThat(connectionFactory.getIdleTimeout())
.isEqualTo(defaultFactory.getIdleTimeout()); .isEqualTo(defaultFactory.getIdleTimeout());
assertThat(connectionFactory.getMaxConnections()) assertThat(connectionFactory.getMaxConnections())
@ -149,8 +145,6 @@ public class ActiveMQAutoConfigurationTests {
assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) assertThat(connectionFactory.getMaximumActiveSessionPerConnection())
.isEqualTo(defaultFactory .isEqualTo(defaultFactory
.getMaximumActiveSessionPerConnection()); .getMaximumActiveSessionPerConnection());
assertThat(connectionFactory.isReconnectOnException())
.isEqualTo(defaultFactory.isReconnectOnException());
assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis())
.isEqualTo( .isEqualTo(
defaultFactory.getTimeBetweenExpirationCheckMillis()); defaultFactory.getTimeBetweenExpirationCheckMillis());
@ -159,18 +153,35 @@ public class ActiveMQAutoConfigurationTests {
}); });
} }
@Test
@Deprecated
public void defaultPooledConnectionFactoryIsAppliedWithDeprecatedSettings() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=true")
.run((context) -> {
assertThat(context.getBeansOfType(PooledConnectionFactory.class))
.hasSize(1);
PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class);
PooledConnectionFactory defaultFactory = new PooledConnectionFactory();
assertThat(connectionFactory.isCreateConnectionOnStartup())
.isEqualTo(defaultFactory.isCreateConnectionOnStartup());
assertThat(connectionFactory.getExpiryTimeout())
.isEqualTo(defaultFactory.getExpiryTimeout());
assertThat(connectionFactory.isReconnectOnException())
.isEqualTo(defaultFactory.isReconnectOnException());
});
}
@Test @Test
public void customPooledConnectionFactoryIsApplied() { public void customPooledConnectionFactoryIsApplied() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=true", .withPropertyValues("spring.activemq.pool.enabled=true",
"spring.activemq.pool.blockIfFull=false", "spring.activemq.pool.blockIfFull=false",
"spring.activemq.pool.blockIfFullTimeout=64", "spring.activemq.pool.blockIfFullTimeout=64",
"spring.activemq.pool.createConnectionOnStartup=false",
"spring.activemq.pool.expiryTimeout=4096",
"spring.activemq.pool.idleTimeout=512", "spring.activemq.pool.idleTimeout=512",
"spring.activemq.pool.maxConnections=256", "spring.activemq.pool.maxConnections=256",
"spring.activemq.pool.maximumActiveSessionPerConnection=1024", "spring.activemq.pool.maximumActiveSessionPerConnection=1024",
"spring.activemq.pool.reconnectOnException=false",
"spring.activemq.pool.timeBetweenExpirationCheck=2048", "spring.activemq.pool.timeBetweenExpirationCheck=2048",
"spring.activemq.pool.useAnonymousProducers=false") "spring.activemq.pool.useAnonymousProducers=false")
.run((context) -> { .run((context) -> {
@ -181,19 +192,35 @@ public class ActiveMQAutoConfigurationTests {
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse(); assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout())
.isEqualTo(64); .isEqualTo(64);
assertThat(connectionFactory.isCreateConnectionOnStartup()).isFalse();
assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096);
assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512); assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512);
assertThat(connectionFactory.getMaxConnections()).isEqualTo(256); assertThat(connectionFactory.getMaxConnections()).isEqualTo(256);
assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) assertThat(connectionFactory.getMaximumActiveSessionPerConnection())
.isEqualTo(1024); .isEqualTo(1024);
assertThat(connectionFactory.isReconnectOnException()).isFalse();
assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis())
.isEqualTo(2048); .isEqualTo(2048);
assertThat(connectionFactory.isUseAnonymousProducers()).isFalse(); assertThat(connectionFactory.isUseAnonymousProducers()).isFalse();
}); });
} }
@Test
@Deprecated
public void customPooledConnectionFactoryIsAppliedWithDeprecatedSettings() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=true",
"spring.activemq.pool.createConnectionOnStartup=false",
"spring.activemq.pool.expiryTimeout=4096",
"spring.activemq.pool.reconnectOnException=false")
.run((context) -> {
assertThat(context.getBeansOfType(PooledConnectionFactory.class))
.hasSize(1);
PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class);
assertThat(connectionFactory.isCreateConnectionOnStartup()).isFalse();
assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096);
assertThat(connectionFactory.isReconnectOnException()).isFalse();
});
}
@Test @Test
public void pooledConnectionFactoryConfiguration() { public void pooledConnectionFactoryConfiguration() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)

@ -941,13 +941,10 @@ content into your application. Rather, pick only the properties that you need.
spring.activemq.packages.trusted= # Comma-separated list of specific packages to trust (when not trusting all packages). spring.activemq.packages.trusted= # Comma-separated list of specific packages to trust (when not trusting all packages).
spring.activemq.pool.block-if-full=true # Whether to block when a connection is requested and the pool is full. Set it to false to throw a "JMSException" instead. spring.activemq.pool.block-if-full=true # Whether to block when a connection is requested and the pool is full. Set it to false to throw a "JMSException" instead.
spring.activemq.pool.block-if-full-timeout=-1ms # Blocking period before throwing an exception if the pool is still full. spring.activemq.pool.block-if-full-timeout=-1ms # Blocking period before throwing an exception if the pool is still full.
spring.activemq.pool.create-connection-on-startup=true # Whether to create a connection on startup. Can be used to warm up the pool on startup.
spring.activemq.pool.enabled=false # Whether a PooledConnectionFactory should be created, instead of a regular ConnectionFactory. spring.activemq.pool.enabled=false # Whether a PooledConnectionFactory should be created, instead of a regular ConnectionFactory.
spring.activemq.pool.expiry-timeout=0ms # Connection expiration timeout.
spring.activemq.pool.idle-timeout=30s # Connection idle timeout. spring.activemq.pool.idle-timeout=30s # Connection idle timeout.
spring.activemq.pool.max-connections=1 # Maximum number of pooled connections. spring.activemq.pool.max-connections=1 # Maximum number of pooled connections.
spring.activemq.pool.maximum-active-session-per-connection=500 # Maximum number of active sessions per connection. spring.activemq.pool.maximum-active-session-per-connection=500 # Maximum number of active sessions per connection.
spring.activemq.pool.reconnect-on-exception=true # Reset the connection when a "JMSException" occurs.
spring.activemq.pool.time-between-expiration-check=-1ms # Time to sleep between runs of the idle connection eviction thread. When negative, no idle connection eviction thread runs. spring.activemq.pool.time-between-expiration-check=-1ms # Time to sleep between runs of the idle connection eviction thread. When negative, no idle connection eviction thread runs.
spring.activemq.pool.use-anonymous-producers=true # Whether to use only one anonymous "MessageProducer" instance. Set it to false to create one "MessageProducer" every time one is required. spring.activemq.pool.use-anonymous-producers=true # Whether to use only one anonymous "MessageProducer" instance. Set it to false to create one "MessageProducer" every time one is required.

@ -5049,6 +5049,8 @@ accordingly, as shown in the following example:
spring.activemq.pool.max-connections=50 spring.activemq.pool.max-connections=50
---- ----
WARNING: `PooledConnectionFactory` is not JMS 2.0 compliant
TIP: See TIP: See
{sc-spring-boot-autoconfigure}/jms/activemq/ActiveMQProperties.{sc-ext}[`ActiveMQProperties`] {sc-spring-boot-autoconfigure}/jms/activemq/ActiveMQProperties.{sc-ext}[`ActiveMQProperties`]
for more of the supported options. You can also register an arbitrary number of beans for more of the supported options. You can also register an arbitrary number of beans

Loading…
Cancel
Save