Polish contribution

Closes gh-5341
pull/3799/merge
Stephane Nicoll 9 years ago
parent 08732fe4c8
commit 25f00b9bb8

@ -107,7 +107,7 @@ public class RabbitAutoConfiguration {
} }
Template template = config.getTemplate(); Template template = config.getTemplate();
Retry retry = template.getRetry(); Retry retry = template.getRetry();
if (retry.isEnable()) { if (retry.isEnabled()) {
RetryTemplate retryTemplate = new RetryTemplate(); RetryTemplate retryTemplate = new RetryTemplate();
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(retry.getMaxAttempts()); retryPolicy.setMaxAttempts(retry.getMaxAttempts());

@ -22,6 +22,7 @@ import java.util.Set;
import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -396,6 +397,7 @@ public class RabbitProperties {
/** /**
* Optional properties for a retry interceptor. * Optional properties for a retry interceptor.
*/ */
@NestedConfigurationProperty
private final ListenerRetry retry = new ListenerRetry(); private final ListenerRetry retry = new ListenerRetry();
public boolean isAutoStartup() { public boolean isAutoStartup() {
@ -462,6 +464,7 @@ public class RabbitProperties {
public static class Template { public static class Template {
@NestedConfigurationProperty
private final Retry retry = new Retry(); private final Retry retry = new Retry();
/** /**
@ -501,16 +504,16 @@ public class RabbitProperties {
/** /**
* Whether or not publishing retries are enabled. * Whether or not publishing retries are enabled.
*/ */
private boolean enable; private boolean enabled;
/** /**
* The maximum number of attempts to publish or deliver a message. * Maximum number of attempts to publish or deliver a message.
*/ */
private int maxAttempts = 3; private int maxAttempts = 3;
/** /**
* The interval between the first and second attempt to publish * Interval between the first and second attempt to publish or deliver
* or deliver a message. * a message.
*/ */
private long initialInterval = 1000L; private long initialInterval = 1000L;
@ -520,16 +523,16 @@ public class RabbitProperties {
private double multiplier = 1.0; private double multiplier = 1.0;
/** /**
* The maximum interval between attempts. * Maximum interval between attempts.
*/ */
private long maxInterval = 10000L; private long maxInterval = 10000L;
public boolean isEnable() { public boolean isEnabled() {
return this.enable; return this.enabled;
} }
public void setEnable(boolean enable) { public void setEnabled(boolean enabled) {
this.enable = enable; this.enabled = enabled;
} }
public int getMaxAttempts() { public int getMaxAttempts() {

@ -91,14 +91,9 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer {
factory.setDefaultRequeueRejected(listenerConfig.getDefaultRequeueRejected()); factory.setDefaultRequeueRejected(listenerConfig.getDefaultRequeueRejected());
} }
ListenerRetry retryConfig = listenerConfig.getRetry(); ListenerRetry retryConfig = listenerConfig.getRetry();
if (retryConfig.isEnable()) { if (retryConfig.isEnabled()) {
RetryInterceptorBuilder<?> builder; RetryInterceptorBuilder<?> builder = (retryConfig.isStateless() ?
if (retryConfig.isStateless()) { RetryInterceptorBuilder.stateless() : RetryInterceptorBuilder.stateful());
builder = RetryInterceptorBuilder.stateless();
}
else {
builder = RetryInterceptorBuilder.stateful();
}
factory.setAdviceChain(builder factory.setAdviceChain(builder
.maxAttempts(retryConfig.getMaxAttempts()) .maxAttempts(retryConfig.getMaxAttempts())
.backOffOptions(retryConfig.getInitialInterval(), .backOffOptions(retryConfig.getInitialInterval(),
@ -106,6 +101,7 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer {
.recoverer(new RejectAndDontRequeueRecoverer()) .recoverer(new RejectAndDontRequeueRecoverer())
.build()); .build());
} }
} }
} }

@ -147,11 +147,11 @@ public class RabbitAutoConfigurationTests {
@Test @Test
public void testRabbitTemplateRetry() { public void testRabbitTemplateRetry() {
load(TestConfiguration.class, "spring.rabbitmq.template.retry.enable:true", load(TestConfiguration.class, "spring.rabbitmq.template.retry.enabled:true",
"spring.rabbitmq.template.retry.max-attempts:4", "spring.rabbitmq.template.retry.maxAttempts:4",
"spring.rabbitmq.template.retry.initial-interval:2000", "spring.rabbitmq.template.retry.initialInterval:2000",
"spring.rabbitmq.template.retry.multiplier:1.5", "spring.rabbitmq.template.retry.multiplier:1.5",
"spring.rabbitmq.template.retry.max-interval:5000", "spring.rabbitmq.template.retry.maxInterval:5000",
"spring.rabbitmq.template.receiveTimeout:123", "spring.rabbitmq.template.receiveTimeout:123",
"spring.rabbitmq.template.replyTimeout:456"); "spring.rabbitmq.template.replyTimeout:456");
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class); RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
@ -248,17 +248,17 @@ public class RabbitAutoConfigurationTests {
@Test @Test
public void testRabbitListenerContainerFactoryWithCustomSettings() { public void testRabbitListenerContainerFactoryWithCustomSettings() {
load(MessageConvertersConfiguration.class, load(MessageConvertersConfiguration.class,
"spring.rabbitmq.listener.retry.enable:true", "spring.rabbitmq.listener.retry.enabled:true",
"spring.rabbitmq.listener.retry.max-attempts:4", "spring.rabbitmq.listener.retry.maxAttempts:4",
"spring.rabbitmq.listener.retry.initial-interval:2000", "spring.rabbitmq.listener.retry.initialInterval:2000",
"spring.rabbitmq.listener.retry.multiplier:1.5", "spring.rabbitmq.listener.retry.multiplier:1.5",
"spring.rabbitmq.listener.retry.max-interval:5000", "spring.rabbitmq.listener.retry.maxInterval:5000",
"spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.autoStartup:false",
"spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.acknowledgeMode:manual",
"spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.concurrency:5",
"spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.maxConcurrency:10",
"spring.rabbitmq.listener.prefetch:40", "spring.rabbitmq.listener.prefetch:40",
"spring.rabbitmq.listener.default-requeue-rejected:false", "spring.rabbitmq.listener.defaultRequeueRejected:false",
"spring.rabbitmq.listener.transactionSize:20"); "spring.rabbitmq.listener.transactionSize:20");
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context
.getBean("rabbitListenerContainerFactory", .getBean("rabbitListenerContainerFactory",

@ -771,10 +771,10 @@ content into your application; rather pick only the properties that you need.
spring.rabbitmq.listener.default-requeue-rejected= # Whether or not to requeue delivery failures; default `true`. spring.rabbitmq.listener.default-requeue-rejected= # Whether or not to requeue delivery failures; default `true`.
spring.rabbitmq.listener.max-concurrency= # Maximum number of consumers. spring.rabbitmq.listener.max-concurrency= # Maximum number of consumers.
spring.rabbitmq.listener.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used). spring.rabbitmq.listener.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used).
spring.rabbitmq.listener.retry.enable= # Set to true to enable stateless retries for listener containers. spring.rabbitmq.listener.retry.enabled= # Whether or not publishing retries are enabled.
spring.rabbitmq.listener.retry.initial-interval=1000 # The interval between the first and second attempt to deliver a message. spring.rabbitmq.listener.retry.initial-interval=1000 # Interval between the first and second attempt to deliver a message.
spring.rabbitmq.listener.retry.max-attempts=3 # The maximum number of attempts to deliver a message. spring.rabbitmq.listener.retry.max-attempts=3 # Maximum number of attempts to deliver a message.
spring.rabbitmq.listener.retry.max-interval=10000 # The maximum number of attempts to deliver a message. spring.rabbitmq.listener.retry.max-interval=10000 # Maximum number of attempts to deliver a message.
spring.rabbitmq.listener.retry.multiplier=1.0 # A multiplier to apply to the previous delivery retry interval. spring.rabbitmq.listener.retry.multiplier=1.0 # A multiplier to apply to the previous delivery retry interval.
spring.rabbitmq.listener.retry.stateless=true # Whether or not retry is stateless or stateful. spring.rabbitmq.listener.retry.stateless=true # Whether or not retry is stateless or stateful.
spring.rabbitmq.listener.transaction-size= # Number of messages to be processed in a transaction. For best results it should be less than or equal to the prefetch count. spring.rabbitmq.listener.transaction-size= # Number of messages to be processed in a transaction. For best results it should be less than or equal to the prefetch count.
@ -786,12 +786,12 @@ content into your application; rather pick only the properties that you need.
spring.rabbitmq.ssl.key-store-password= # Password used to access the key store. spring.rabbitmq.ssl.key-store-password= # Password used to access the key store.
spring.rabbitmq.ssl.trust-store= # Trust store that holds SSL certificates. spring.rabbitmq.ssl.trust-store= # Trust store that holds SSL certificates.
spring.rabbitmq.ssl.trust-store-password= # Password used to access the trust store. spring.rabbitmq.ssl.trust-store-password= # Password used to access the trust store.
spring.rabbitmq.template.receiveTimeout=0 # Timeout for `receive()` methods. spring.rabbitmq.template.receive-timeout=0 # Timeout for `receive()` methods.
spring.rabbitmq.template.replyTimeout=5000 # Timeout for `sendAndReceive()` methods. spring.rabbitmq.template.reply-timeout=5000 # Timeout for `sendAndReceive()` methods.
spring.rabbitmq.template.retry.enable= # Set to true to enable retries in the `RabbitTemplate`. spring.rabbitmq.template.retry.enabled= # Set to true to enable retries in the `RabbitTemplate`.
spring.rabbitmq.template.retry.initial-interval=1000 # The interval between the first and second attempt to publish a message. spring.rabbitmq.template.retry.initial-interval=1000 # Interval between the first and second attempt to publish a message.
spring.rabbitmq.template.retry.max-attempts=3 # The maximum number of attempts to publish a message. spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to publish a message.
spring.rabbitmq.template.retry.max-interval=10000 # The maximum number of attempts to publish a message. spring.rabbitmq.template.retry.max-interval=10000 # Maximum number of attempts to publish a message.
spring.rabbitmq.template.retry.multiplier=1.0 # A multiplier to apply to the previous publishing retry interval. spring.rabbitmq.template.retry.multiplier=1.0 # A multiplier to apply to the previous publishing retry interval.
spring.rabbitmq.username= # Login user to authenticate to the broker. 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.virtual-host= # Virtual host to use when connecting to the broker.

@ -3801,9 +3801,8 @@ automatically to the auto-configured `AmqpTemplate`.
Any `org.springframework.amqp.core.Queue` that is defined as a bean will be automatically Any `org.springframework.amqp.core.Queue` that is defined as a bean will be automatically
used to declare a corresponding queue on the RabbitMQ instance if necessary. used to declare a corresponding queue on the RabbitMQ instance if necessary.
You can enable retries on the `AmqpTemplate` to retry operations, for example in the event the broker connection is You can enable retries on the `AmqpTemplate` to retry operations, for example in the event
lost. the broker connection is lost. Retries are disabled by default.
Retries are disabled by default.
[[boot-features-using-amqp-receiving]] [[boot-features-using-amqp-receiving]]
==== Receiving a message ==== Receiving a message

Loading…
Cancel
Save