diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index f7092c029ea..b41af45d4a5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -139,17 +139,17 @@ public class RabbitAutoConfiguration { CachingConnectionFactory connectionFactory = new CachingConnectionFactory( factory.getObject()); connectionFactory.setAddresses(config.getAddresses()); - if (config.getChannelCacheSize() != null) { - connectionFactory.setChannelCacheSize(config.getChannelCacheSize()); + if (config.getCache().getChannel().getSize() != null) { + connectionFactory.setChannelCacheSize(config.getCache().getChannel().getSize()); } - if (config.getCacheMode() != null) { - connectionFactory.setCacheMode(config.getCacheMode()); + if (config.getCache().getConnection().getMode() != null) { + connectionFactory.setCacheMode(config.getCache().getConnection().getMode()); } - if (config.getConnectionCacheSize() != null) { - connectionFactory.setConnectionCacheSize(config.getConnectionCacheSize()); + if (config.getCache().getConnection().getSize() != null) { + connectionFactory.setConnectionCacheSize(config.getCache().getConnection().getSize()); } - if (config.getChannelCheckoutTimeout() != null) { - connectionFactory.setChannelCheckoutTimeout(config.getChannelCheckoutTimeout()); + if (config.getCache().getChannel().getCheckoutTimeout() != null) { + connectionFactory.setChannelCheckoutTimeout(config.getCache().getChannel().getCheckoutTimeout()); } return connectionFactory; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 203a4a38bb1..94f40a62f18 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -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. @@ -78,26 +78,9 @@ public class RabbitProperties { private Integer requestedHeartbeat; /** - * The number of channels to retain in the cache, or max channels per connection - * when channelCheckoutTimeout is > 0. + * Cache configuration. */ - private Integer channelCacheSize; - - /** - * The connection factory cache mode; CHANNEL (default) or CONNECTION. - */ - private CacheMode cacheMode; - - /** - * The number of connections to cache (only applies when cacheMode is CONNECTION). - */ - private Integer connectionCacheSize; - - /** - * The number of milliseconds to wait to obtain a channel if the channelCacheSize - * has been reached; if 0, always create a new channel. - */ - private Long channelCheckoutTimeout; + private final Cache cache = new Cache(); /** * Listener container configuration. @@ -210,36 +193,8 @@ public class RabbitProperties { this.requestedHeartbeat = requestedHeartbeat; } - public Integer getChannelCacheSize() { - return this.channelCacheSize; - } - - public void setChannelCacheSize(Integer channelCacheSize) { - this.channelCacheSize = channelCacheSize; - } - - public CacheMode getCacheMode() { - return this.cacheMode; - } - - public void setCacheMode(CacheMode cacheMode) { - this.cacheMode = cacheMode; - } - - public Integer getConnectionCacheSize() { - return this.connectionCacheSize; - } - - public void setConnectionCacheSize(Integer connectionCacheSize) { - this.connectionCacheSize = connectionCacheSize; - } - - public Long getChannelCheckoutTimeout() { - return this.channelCheckoutTimeout; - } - - public void setChannelCheckoutTimeout(Long channelCheckoutTimeout) { - this.channelCheckoutTimeout = channelCheckoutTimeout; + public Cache getCache() { + return this.cache; } public Listener getListener() { @@ -315,6 +270,84 @@ public class RabbitProperties { } + public static class Cache { + + private final Channel channel = new Channel(); + + private final Connection connection = new Connection(); + + public Channel getChannel() { + return this.channel; + } + + public Connection getConnection() { + return this.connection; + } + + public static class Channel { + + /** + * Number of channels to retain in the cache. When "check-timeout" > 0, max + * channels per connection. + */ + private Integer size; + + /** + * Number of milliseconds to wait to obtain a channel if the cache size + * has been reached. If 0, always create a new channel. + */ + private Long checkoutTimeout; + + public Integer getSize() { + return this.size; + } + + public void setSize(Integer size) { + this.size = size; + } + + public Long getCheckoutTimeout() { + return this.checkoutTimeout; + } + + public void setCheckoutTimeout(Long checkoutTimeout) { + this.checkoutTimeout = checkoutTimeout; + } + + } + + public static class Connection { + + /** + * Connection factory cache mode. + */ + private CacheMode mode = CacheMode.CHANNEL; + + /** + * Number of connections to cache. Only applies when mode is CONNECTION. + */ + private Integer size; + + public CacheMode getMode() { + return this.mode; + } + + public void setMode(CacheMode mode) { + this.mode = mode; + } + + public Integer getSize() { + return this.size; + } + + public void setSize(Integer size) { + this.size = size; + } + + } + + } + public static class Listener { /** diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index aa38580ad0c..82b3816b073 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -154,10 +154,10 @@ public class RabbitAutoConfigurationTests { @Test public void testConnectionFactoryCacheSettings() { load(TestConfiguration.class, - "spring.rabbitmq.channelCacheSize=23", - "spring.rabbitmq.cacheMode=CONNECTION", - "spring.rabbitmq.connectionCacheSize=2", - "spring.rabbitmq.channelCheckoutTimeout=1000"); + "spring.rabbitmq.cache.channel.size=23", + "spring.rabbitmq.cache.channel.checkoutTimeout=1000", + "spring.rabbitmq.cache.connection.mode=CONNECTION", + "spring.rabbitmq.cache.connection.size=2"); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index c01feeb5c6c..7fd0b7d9445 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -756,6 +756,10 @@ content into your application; rather pick only the properties that you need. # RABBIT ({sc-spring-boot-autoconfigure}/amqp/RabbitProperties.{sc-ext}[RabbitProperties]) spring.rabbitmq.addresses= # Comma-separated list of addresses to which the client should connect. + spring.rabbitmq.cache.channel.checkout-timeout= # Number of milliseconds to wait to obtain a channel if the cache size has been reached. + spring.rabbitmq.cache.channel.size= # Number of channels to retain in the cache. + spring.rabbitmq.cache.connection.mode= # Connection factory cache mode. + spring.rabbitmq.cache.connection.size= # Number of connections to cache. spring.rabbitmq.dynamic=true # Create an AmqpAdmin bean. spring.rabbitmq.host=localhost # RabbitMQ host. spring.rabbitmq.listener.acknowledge-mode= # Acknowledge mode of container. @@ -774,10 +778,6 @@ content into your application; rather pick only the properties that you need. spring.rabbitmq.ssl.trust-store-password= # Password used to access the trust store. spring.rabbitmq.username= # Login user to authenticate to the broker. spring.rabbitmq.virtual-host= # Virtual host to use when connecting to the broker. - spring.rabbitmq.cacheMode= # The connection factory cache mode; CHANNEL (default) or CONNECTION. - spring.rabbitmq.channelCacheSize= # The number of channels to retain in the cache, or max channels per connection when `channelCheckoutTimeout` is > 0. - spring.rabbitmq.connectionCacheSize= # The number of connections to cache (only applies when cacheMode is CONNECTION). - spring.rabbitmq.channelCheckoutTimeout= # The number of milliseconds to wait to obtain a channel if the channelCacheSize has been reached; if 0, always create a new channel. # ---------------------------------------- # ACTUATOR PROPERTIES